Board index » delphi » connection string

connection string


2004-02-04 07:54:28 PM
delphi222
Hi,
does anyone know any url or ftp site where I can get extensive information
about connection strings for ADO(how to build them, what every field is,
which options you can include, etc)?
Thanks for help & best regards
Guillem
 
 

Re:connection string

MS SQL Server Books On-Line,
Microsoft Data Access Components,
ActiveXR Data Objects (ADO)
 

Re:connection string

Quote
does anyone know any url or ftp site where I can get extensive information
about connection strings for ADO(how to build them, what every field is,
which options you can include, etc)?
Some examples here of connection strings
www.able-consulting.com/ADO_Conn.htm
--
Mike Collier
FREE ADO Inspector tool when you register at ADO forum.
www.adoanywhere.com
www.adoanywhere.com/forum
 

Re:connection string

thanks both for your help!
Guillem
 

Re:connection string

I am new to ADO and have successfully ported a fairly large DB4 application
to MS SQL server. Everything works great but I need to programatically set
my connection string ... does someone have some sample code that creates a
connection string (i.e. reads the ODBC so I can set the provider, Data
Source etc.) or can someone point me to a document that explains where to
retrieve the parameters I need to create the ConnectionString? All of the
sample ADO apps in the Delphi demos have the strings precoded. I am using
Delphi 7 and MS SQL Server 7. thanks in advance, LL
 

Re:connection string

You can use the TADOConnection in Delphi 7 to create your connectionstring,
simple right-click for "edit CommandString"
"Lon Layton" <XXXX@XXXXX.COM>writes
Quote
I am new to ADO and have successfully ported a fairly large DB4
application
to MS SQL server. Everything works great but I need to programatically
set
my connection string ... does someone have some sample code that creates a
connection string (i.e. reads the ODBC so I can set the provider, Data
Source etc.) or can someone point me to a document that explains where to
retrieve the parameters I need to create the ConnectionString? All of the
sample ADO apps in the Delphi demos have the strings precoded. I am using
Delphi 7 and MS SQL Server 7. thanks in advance, LL


 

Re:connection string

Lon Layton writes:
Quote
I am new to ADO and have successfully ported a fairly large DB4 application
to MS SQL server. Everything works great but I need to programatically set
my connection string ... does someone have some sample code that creates a
connection string (i.e. reads the ODBC so I can set the provider, Data
Source etc.) or can someone point me to a document that explains where to
retrieve the parameters I need to create the ConnectionString?
To connect via ODBC you don't have to extract any information
about the DSN to build a connection string if you only have
the DSN; simply create a connection string like this:
CnnStr := 'Provider=MSDASQL;' +
'Persist Security Info=False;' +
'Data Source=' + DSNName;
(You can also add 'User ID=XXX;' as with other connection
strings).
But ODBC adds additional overhead, I would recommend using the
sqloledb provider to connect to SQL Server.
For SQL Server it is pretty simple. Create a login form for the
user to enter a server name [1], their login details and the
database name. You need to allow them to select "Windows NT
Authentication" or "SQL Authentication"
The basic connection string will be
CnnStr := 'Provider=sqloledb;' +
'Data Source=' + ServerName + ';' +
'Initial Catalog=' + DatabaseName + ';';
For the former login method you append:
CnnStr := CnnStr + 'Integrated Security=SSPI;'
for SQL logins you append:
CnnStr := CnnStr +
'User Id=' + Username + ';' +
'Password=' + Password + ';';
[1] Lots of threads exist on how to return a list of available
servers, and how to get the list of databases on a server.
--
jc
Remove the -not from email
 

Re:connection string

that is a big help ... but I need to see a list of DSNs ... I cannot be
certain that every customer will name the Dataset the same. How can I
display a list of DSNs so I can have my user select one? thanks,LL
"Jeremy Collins" <XXXX@XXXXX.COM>writes
Quote
Lon Layton writes:
>I am new to ADO and have successfully ported a fairly large DB4
application
>to MS SQL server. Everything works great but I need to programatically
set
>my connection string ... does someone have some sample code that creates
a
>connection string (i.e. reads the ODBC so I can set the provider, Data
>Source etc.) or can someone point me to a document that explains where
to
>retrieve the parameters I need to create the ConnectionString?

To connect via ODBC you don't have to extract any information
about the DSN to build a connection string if you only have
the DSN; simply create a connection string like this:

CnnStr := 'Provider=MSDASQL;' +
'Persist Security Info=False;' +
'Data Source=' + DSNName;

(You can also add 'User ID=XXX;' as with other connection
strings).

But ODBC adds additional overhead, I would recommend using the
sqloledb provider to connect to SQL Server.

For SQL Server it is pretty simple. Create a login form for the
user to enter a server name [1], their login details and the
database name. You need to allow them to select "Windows NT
Authentication" or "SQL Authentication"

The basic connection string will be

CnnStr := 'Provider=sqloledb;' +
'Data Source=' + ServerName + ';' +
'Initial Catalog=' + DatabaseName + ';';

For the former login method you append:
CnnStr := CnnStr + 'Integrated Security=SSPI;'

for SQL logins you append:
CnnStr := CnnStr +
'User Id=' + Username + ';' +
'Password=' + Password + ';';

[1] Lots of threads exist on how to return a list of available
servers, and how to get the list of databases on a server.

--
jc

Remove the -not from email
 

Re:connection string

Lon Layton writes:
Quote
that is a big help ... but I need to see a list of DSNs ... I cannot be
certain that every customer will name the Dataset the same. How can I
display a list of DSNs so I can have my user select one? thanks,LL
They are in the registry:
procedure GetDSNs(s : TStrings);
var
Reg : TRegistry;
s2 : TStringList;
i : integer;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', False) then
Reg.GetValueNames(s);
Reg.CloseKey;
s2 := TStringList.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', False)
then
Reg.GetValueNames(s2);
Reg.CloseKey;
for i := 0 to s2.Count - 1 do
s.Add(s2[i]);
finally
s2.Free;
end;
finally
Reg.Free;
end;
end;
--
jc
Remove the -not from email
 

Re:connection string

Thanks a ton! that is exactly what I need! LL
"Jeremy Collins" <XXXX@XXXXX.COM>writes
Quote
Lon Layton writes:

>that is a big help ... but I need to see a list of DSNs ... I cannot be
>certain that every customer will name the Dataset the same. How can I
>display a list of DSNs so I can have my user select one? thanks,LL

They are in the registry:

procedure GetDSNs(s : TStrings);
var
Reg : TRegistry;
s2 : TStringList;
i : integer;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', False)
then
Reg.GetValueNames(s);

Reg.CloseKey;

s2 := TStringList.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', False)
then
Reg.GetValueNames(s2);

Reg.CloseKey;

for i := 0 to s2.Count - 1 do
s.Add(s2[i]);
finally
s2.Free;
end;
finally
Reg.Free;
end;
end;


--
jc

Remove the -not from email
 

Re:connection string

You can have a look at the PromptDatasource command. It brings up the
DataLink properties window. It is in the AdoDB unit.
George Christoforakis.
"Lon Layton" <XXXX@XXXXX.COM>writes
Quote
I am new to ADO and have successfully ported a fairly large DB4
application
to MS SQL server. Everything works great but I need to programatically
set
my connection string ... does someone have some sample code that creates a
connection string (i.e. reads the ODBC so I can set the provider, Data
Source etc.) or can someone point me to a document that explains where to
retrieve the parameters I need to create the ConnectionString? All of the
sample ADO apps in the Delphi demos have the strings precoded. I am using
Delphi 7 and MS SQL Server 7. thanks in advance, LL


 

Re:connection string

Quote
... does someone have some sample code that creates a
connection string (i.e. reads the ODBC so I can set the provider, Data
Source etc.) or can someone point me to a document that explains where to
retrieve the parameters I need to create the ConnectionString?
Since you are using SQL Server, use the OLEDB provider for it and not
ODBC-ADO provider. ODBC has been deprecated.
--
Mike Collier
www.adoanywhere.com
"Lon Layton" <XXXX@XXXXX.COM>writes
Quote
I am new to ADO and have successfully ported a fairly large DB4
application
to MS SQL server. Everything works great but I need to programatically
set
my connection string ... does someone have some sample code that creates a
connection string (i.e. reads the ODBC so I can set the provider, Data
Source etc.) or can someone point me to a document that explains where to
retrieve the parameters I need to create the ConnectionString? All of the
sample ADO apps in the Delphi demos have the strings precoded. I am using
Delphi 7 and MS SQL Server 7. thanks in advance, LL


 

Re:connection string

If I set the Connection String of an ADOConnection at run time, the provider
does not seem to always get set correctly.
I let the user set it up using the win api function GetInitializationString.
Is there a way I can get the Provider Name from this function and set it
manually in the control?
Thanks
 

Re:connection string

I am developing a ECO Server application that needs to connect to an
Interbase server.
At present when I plonk my ECO server on a PC with Interbase I get the
following error:
"The located assembly's manifest definition with name
'Borland.Data.Interbase' does not match the assembly reference"
I presume that this is the result of the ConnectionString to the
database not being correct?
The connection string created inside Delphi for connecting to the
database from my development PC is:
database=N:\Data\DATA.GDB;
assembly=Borland.Data.Interbase,
Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=91d62ebb5b0d1b1b;
vendorclient=gds32.dll;
provider=Interbase;
username=sysdba;
password=masterkey
This works fine when connecting from my development PC. When I moved
the ECO Server to the same PC as Interbase I changed the line
"database=N:\Data\DATA.GDB;" to reflect the location of the database
file on that PC. This results in the error above.
What else do I need to do?
Kind regards
Sean
 

Re:connection string

Quote
I am developing a ECO Server application that needs to connect to an Interbase server.

At present when I plonk my ECO server on a PC with Interbase I get the following error:

"The located assembly's manifest definition with name 'Borland.Data.Interbase' does not match the
assembly reference"

I presume that this is the result of the ConnectionString to the database not being correct?

The connection string created inside Delphi for connecting to the database from my development PC
is:

database=N:\Data\DATA.GDB;
assembly=Borland.Data.Interbase,
Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=91d62ebb5b0d1b1b;
vendorclient=gds32.dll;
provider=Interbase;
username=sysdba;
password=masterkey

This works fine when connecting from my development PC. When I moved the ECO Server to the same
PC as Interbase I changed the line "database=N:\Data\DATA.GDB;" to reflect the location of the
database file on that PC. This results in the error above.
Do you really have physical disk N: installed on your server ?
ivan