Board index » delphi » Connectiion to sql2000 / sql2005 express

Connectiion to sql2000 / sql2005 express


2007-02-14 03:03:35 PM
delphi183
Platform - Delphi 7, sql2000, sql2005 epxress,ADO
I have two database ,one attach to SQL 2000 in server1, the other attach to
SQL2005 express in server2,
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;User
ID=xx;Password=xx;Data Source=server1;Initial Catalog=db'
This works fine in server 1 .
Connect to Server2 works only if I change to
'Datasource='server2\SQLEXPRESS' instead of 'Datasource=server2' . My
question is :
How do I retrieve the SQL server name , so that one connection string work
for two environment , and I need not hardcode 'SQLEXPRESS' in order to
connect to sql2005 .
( ** SERVER1 ,SERVER2 is computername )
Very much thanks .
KG
 
 

Re:Connectiion to sql2000 / sql2005 express

The real problem is that ADO connections to SQL2005 need to use a different
provider as in "SQLNCLI.1" and SQL2000 uses "SQLOLEDB.1"
 

Re:Connectiion to sql2000 / sql2005 express

The only way I can think to do this would be to create a client side alias
that alias's the named instance in Server2, but I suspect that will not work
because the alias will have to be to machine name which will get resolved
somewhere in the protocol stack.
why is this a problem for you in the first place? You are hardwiring the
server name in the connection strings, sqlexpress is just the sql server
specific part of the name. In reality ha dpeople not been lazy when building
the protocol stack originball you would probably have had to connect to
server1\MS SQL because thats what you are actually doing, connecting to a
specific instance (pre sql 2000 there could only be one but thats not the
point) of sql server running on a specific machine.
Oh and Dennis is not 100% right, it is preferable to use sqlncli over
sqloledb when connecting to a 2005 instance but it will work as long as you
don't try and use new features.
"KG" <XXXX@XXXXX.COM>writes
Quote
Platform - Delphi 7, sql2000, sql2005 epxress,ADO
I have two database ,one attach to SQL 2000 in server1, the other attach
to SQL2005 express in server2,
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;User
ID=xx;Password=xx;Data Source=server1;Initial Catalog=db'
This works fine in server 1 .
Connect to Server2 works only if I change to
'Datasource='server2\SQLEXPRESS' instead of 'Datasource=server2' . My
question is :
How do I retrieve the SQL server name , so that one connection string work
for two environment , and I need not hardcode 'SQLEXPRESS' in order to
connect to sql2005 .
( ** SERVER1 ,SERVER2 is computername )
Very much thanks .


KG

 

Re:Connectiion to sql2000 / sql2005 express

KG skrev:
Quote
Platform - Delphi 7, sql2000, sql2005 epxress,ADO
I have two database ,one attach to SQL 2000 in server1, the other attach to
SQL2005 express in server2,
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;User
ID=xx;Password=xx;Data Source=server1;Initial Catalog=db'
This works fine in server 1 .
Connect to Server2 works only if I change to
'Datasource='server2\SQLEXPRESS' instead of 'Datasource=server2' . My
question is :
How do I retrieve the SQL server name , so that one connection string work
for two environment , and I need not hardcode 'SQLEXPRESS' in order to
connect to sql2005 .
( ** SERVER1 ,SERVER2 is computername )
Very much thanks .

When you install sql2005 you have an option to install it as the
"default" instance.
If you do that you will be able to connect to the server running sql2005
using only the computer name.
/Micke
 

Re:Connectiion to sql2000 / sql2005 express

Hi all,
Thanks for your efforts expecially Micke . I have reinstalled sqlServer as
default instance instead of name instance and get the things done . For
backward compatible purpose , I used sqlOleDb instead of the new sqlncli .
"Mikael Eriksson" <XXXX@XXXXX.COM>writes
Quote
KG skrev:
>Platform - Delphi 7, sql2000, sql2005 epxress,ADO
>I have two database ,one attach to SQL 2000 in server1, the other attach
>to SQL2005 express in server2,
>ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;User
>ID=xx;Password=xx;Data Source=server1;Initial Catalog=db'
>This works fine in server 1 .
>Connect to Server2 works only if I change to
>'Datasource='server2\SQLEXPRESS' instead of 'Datasource=server2' . My
>question is :
>How do I retrieve the SQL server name , so that one connection string
>work for two environment , and I need not hardcode 'SQLEXPRESS' in order
>to connect to sql2005 .
>( ** SERVER1 ,SERVER2 is computername )
>Very much thanks .
>

When you install sql2005 you have an option to install it as the "default"
instance.
If you do that you will be able to connect to the server running sql2005
using only the computer name.

/Micke