Thread View: borland.public.cppbuilder.database.multi-tier
5 messages
5 total messages
Started by Gerhard Behnke
Fri, 26 Mar 2004 15:23
Send a username/password to the DataSnap-Server
Author: Gerhard Behnke
Date: Fri, 26 Mar 2004 15:23
Date: Fri, 26 Mar 2004 15:23
7 lines
1186 bytes
1186 bytes
I need a simple example how to set the username of the Database from my DatasSnap Client to the DataSnap Server. I try'd to do it with adding a Property to the Type Library but without success. It would be great if anyone has done this and can send me how to do Many thanks in advance Gerhard
Re: Send a username/password to the DataSnap-Server
Author: Sydney Delieu
Date: Wed, 31 Mar 2004 00:27
Date: Wed, 31 Mar 2004 00:27
91 lines
3789 bytes
3789 bytes
Hi Gerhard,
Open your Type Library editor, then right click on your Interface (ie.
ISomeServer), then select NEW, and then METHOD. Give the method a
meaningful name (eg. UserLogon). Select the new method you have just
created, then in the right hand pane click on the PARAMETERS tab. From
here, enter two parameters of type BSTR (eg. UserName, Password).
Find the implementation of your newly created method (eg. in
SomeServerImpl.cpp), and add the code to set connection strings etc..
For example, if you have a Remote Data Module containing a
TADOConnection and you wish to set the connection string on the server:
STDMETHODIMP TSomeServerImpl::UserLogon(BSTR UserName, BSTR Password)
{
WideString ws;
ws = "";
try {
m_DataModule->adoConn->Connected = false;
m_DataModule->adoConn->ConnectionString = "";
ws = "Provider=SQLOLEDB;User ID=";
ws = ws + UserName;
ws = ws + ";Password=" + Password;
ws = ws + ";Persist Security Info=false;";
ws = ws + "Initial Catalog=HBBB;";
ws = ws + "Data Source=127.0.0.1;";
ws = ws + "User Procedure for Prepare=1;Auto Translate=True;";
ws = ws + "Packet Size=4096;Workstation ID=RepAppServer;";
ws = ws + "Use Encryption for Data=False;";
ws = ws + "Tag with column collation when possible=False";
m_DataModule->adoConn->ConnectionString = ws;
m_DataModule->adoConn->Connected = true;
}
catch (Exception &e) {
frmMainForm->memoOutput->Lines->Add(e.Message.c_str());
return Error(e.Message.c_str(), IID_ISomeServer);
}
return S_OK;
}
I am using BCB6 Enterprise with SP4, and have found that you also need
to add the following to the header file for the implementation (using
the above example, SomeServerImpl.h):
regObj.Singleton = false;
regObj.EnableWeb = true;
regObj.EnableSocket = true;
regObj.RegisterPooled = false; // This is the line you must add.
return regObj.UpdateRegistry(bRegister);
If you don't add that line, it means connections will be 'pooled', so
if one client successfully logs on, many clients will be able to use
the same credentials without providing any credentials.
On the client side, you can call the method using (I'm using a
TWebConnection to connect to SomeServer using HTTPS over the Internet,
it's pretty much the same for a TDCOMConnection though):
void __fastcall TfrmMainForm::cmdLogonClick(TObject *Sender)
{
connWeb->Connected = false;
connWeb->Connected = true;
IDispatch *disp = (IDispatch*)connWeb->AppServer;
ISomeServerDisp TempInterface((ISomeServer*)disp);
Screen->Cursor = crHourGlass;
try {
if (TempInterface.UserLogon(
AnsiToOLESTR(txtUsername->Text.c_str()),
AnsiToOLESTR(txtPassword->Text.c_str())) != S_OK) {
Application->MessageBox("There was a problem", "PROBLEM", MB_OK);
}
}
__finally {
Screen->Cursor = crDefault;
}
}
Hope that this helps.
Regards,
Syd.
Re: Send a username/password to the DataSnap-Server
Author: vavan
Date: Wed, 31 Mar 2004 07:29
Date: Wed, 31 Mar 2004 07:29
45 lines
2754 bytes
2754 bytes
On 30 Mar 2004 16:27:55 -0800, "Sydney Delieu" <syddel@hotmail.com>
wrote:
> m_DataModule->adoConn->ConnectionString = "";
>
> ws = "Provider=SQLOLEDB;User ID=";
> ws = ws + UserName;
> ws = ws + ";Password=" + Password;
> ws = ws + ";Persist Security Info=false;";
> ws = ws + "Initial Catalog=HBBB;";
> ws = ws + "Data Source=127.0.0.1;";
> ws = ws + "User Procedure for Prepare=1;Auto Translate=True;";
> ws = ws + "Packet Size=4096;Workstation ID=RepAppServer;";
> ws = ws + "Use Encryption for Data=False;";
> ws = ws + "Tag with column collation when possible=False";
>
> m_DataModule->adoConn->ConnectionString = ws;
> m_DataModule->adoConn->Connected = true;
instead of somewhat awkward method of concatenating parts of
connection string one can simply use .udl file to set it up
m_DataModule->ADOConnection->LoginPrompt=0;
m_DataModule->ADOConnection->ConnectionString=String("FILE
NAME=")+ExtractFilePath(Application->ExeName)+"MyConnection.udl";
m_DataModule->ADOConnection->Open(UserName,Password);
had you done that you do not need to recompile appserver in order to
change some connection settings
just a hint though :)
> if (TempInterface.UserLogon(
> AnsiToOLESTR(txtUsername->Text.c_str()),
> AnsiToOLESTR(txtPassword->Text.c_str())) != S_OK) {
another hint is to use WideString variables instead of manually
convert parameters to pass them to COM object
and third (and last) is to implement ISupportErrorInfo interface in
your appserver to let pass exception info back to the client and show
there instead of mysterious "There was a problem" ;)
--
Vladimir Ulchenko aka vavan
Re: Send a username/password to the DataSnap-Server
Author: Sydney Delieu
Date: Wed, 31 Mar 2004 22:27
Date: Wed, 31 Mar 2004 22:27
8 lines
1049 bytes
1049 bytes
Hi Vladimir, Thanks for the hints! Could you please explain how to implement ISupportErrorInfo in the AppServer and how to read the descriptive error from the client? Thanks, Syd.
Re: Send a username/password to the DataSnap-Server
Author: vavan
Date: Thu, 01 Apr 2004 07:20
Date: Thu, 01 Apr 2004 07:20
40 lines
2419 bytes
2419 bytes
On 31 Mar 2004 14:27:56 -0800, "Sydney Delieu" <syddel@hotmail.com>
wrote:
>Thanks for the hints! Could you please explain how to implement
>ISupportErrorInfo in the AppServer and how to read the descriptive
>error from the client?
I believe that actually it should have already been implemented
somewhere in IAppServer but see the little snippet below to have some
ideas how one can achieve that for COM object in general using ATL
class ATL_NO_VTABLE TrdmWorkflowImpl:
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<TrdmWorkflowImpl, &CLSID_rdmWorkflow>,
public IAppServerImpl<TrdmWorkflow, TrdmWorkflowImpl, IrdmWorkflow,
&IID_IrdmWorkflow, LIBID_OF_rdmWorkflow>,
public ISupportErrorInfoImpl <&IID_IrdmWorkflow>
{
public:
BEGIN_COM_MAP(TrdmWorkflowImpl)
RDMOBJECT_COM_INTERFACE_ENTRIES(IrdmWorkflow)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()
then on client side you can use code similar to following
void DISPCHECK(HRESULT hr,const EXCEPINFO &ei){
if(S_OK!=hr)
throw
EOleException(String(ei.bstrDescription),ei.wCode,String(ei.bstrSource),String(ei.bstrHelpFile),ei.dwHelpContext);
}
and smth like
DISPCHECK(IMyAppServ.Connect(wsUserName,wsPassword,&wsSessionId,&iRes),IMyAppServ.excepinfo);
HTH
--
Vladimir Ulchenko aka vavan
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads