ConnectionString issues - SQL Server 2008 on Windo

2019-09-01 03:17发布

问题:

We have a third party program that used to run on Windows 2003 against SQL Server 2000 database (app and db are on same machine). We are trying to migrate/install it on Windows 2008/ SQL Server 2008.

The connection string as specified does not seem to allow it to connect it to SQL Server (see below)

    <Configuration name="PROG">
    <ADOConnection>
        Provider=SQLOLEDB.1;Persist Security Info=False;User Id=sa;Pwd=p@ssw0rd;Initial Catalog=DB_NEW;Data source=servername
    </ADOConnection>
</Configuration>

I tried an alternate one and that also does not work

<Configuration name="PROG">
     <ADOConnection>    
Provider=SQLNCLI10.1;Persist Security Info=False;Initial Catalog=DB_NEW;Data Source=servername;Uid=sa; Pwd=p@ssw0rd;

I was able to use the one below to successfully connect the application to a SQL Server 2008 database on Windows 2003

<Configuration name="PROG">
    <ADOConnection>
        Provider=SQLOLEDB.1;Persist Security Info=False;User Id=sa;Pwd=p@ssw0rd;Initial Catalog=DB_NEW;Data source=servername
    </ADOConnection>

What is the right syntax to get the application to connect to a SQL Server 2008 on Windows 2008 server?

回答1:

You can check which provider version(s) are installed by looking in the registry: HKEY_CLASSES_ROOT\SQLNCLI10\Clsid

HKEY_CLASSES_ROOT\SQLNCLI10.1\Clsid (for version 10.1 etc)

The SQLNCLI10 (sql server native client) name is an alias to the latest version installed on the computer. On your 2003 box you will also find entries for sqloledb in the registry which you likely won't have installed on the 2008 box.

I would expect that the following should work: Provider=SQLNCLI10;Persist Security Info=False;User Id=sa;Pwd=p@ssw0rd;Initial Catalog=DB_NEW;Data source=servername

For more info on the formatting of the connection string and the various provider see: this connectionstring site