Article View: borland.public.cppbuilder.database.multi-tier
Article #56Re: Send a username/password to the DataSnap-Server
From: 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.
Technical Details
Message-ID:
<406a108b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40644ae9$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcd2b,2bd86f456036fab5 X-Google-Attributes: gidfcd2b,public X-Google-ArrivalTime: 2004-03-30 16:32:33 PST From: "Sydney Delieu" <syddel@hotmail.com> Subject: Re: Send a username/password to the DataSnap-Server Newsgroups: borland.public.cppbuilder.database.multi-tier References: <40644ae9$1@newsgroups.borland.com> User-Agent: XanaNews/1.16.1.13 NNTP-Posting-Host: 82.0.117.59 Message-ID: <406a108b$1@newsgroups.borland.com> Date: 30 Mar 2004 16:27:55 -0800 X-Trace: newsgroups.borland.com 1080692875 82.0.117.59 (30 Mar 2004 16:27:55 -0800) Lines: 92 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail