sqlserver2008远程连接不了

sqlserver2008远程连接不了,第1张

概述这两天要把以前连接sqlserver2000的程序搬到sqlserver2008下,遇到的一系列问题: 1.原来的连接字符串不行了 strSQL.Format("%s","PROVIDER=SQLOLEDB;SERVER=.;DATABASE=studentinfo;UID=sa;PWD=");//这个是2000下面的是可以的 后来发现还是SERVER这里写错了,一定要把全程写下来(包括计算机名称

这两天要把以前连接sqlserver2000的程序搬到sqlserver2008下,遇到的一系列问题:

1.原来的连接字符串不行了

strsql.Format("%s","PROVIDER=sqlolEDB;SERVER=.;DATABASE=studentinfo;UID=sa;PWD=");//这个是2000下面的是可以的

后来发现还是SERVER这里写错了,一定要把全程写下来(包括计算机名称),用localhost及127.0.0.1或本机IP都不行。如果想采用IP形式则需在host文件中解析一下,方法:http://blog.csdn.net/nanfeiyannan/article/details/6607733

如果字符串不正确,则会报错:Idispatch error #3149或UnkNown error 0x800A0E7A 或“未指定的错误”

2.远程连接时,vc中可以连接,直接采用数据库中新建连接的方法不行,java也连接不了(因为java中需要端口号)

把防火墙关闭或设置例外端口号,如果1433被其他占了(如电脑上存在以前安装的其他sqlserver2000等版本),则需要设一个其他端口号。此时需要

在客户端程序的连接地址设置成: “服务器IP,1433\sql2008” 就可以了
另附一份vc下连接sqlserver的字符串大全:

Standard Security

Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

Use servername\instancename as Data Source to connect to a specific sqlServer instance.

Are you using sql Server 2008 Express? Don't miss the server name SyntaxServername\sqlEXPRESS where you substitute Servername with the name of thecomputer where the sql Server Express installation resIDes.

 

Standard Security alternative Syntax

This connection string produce the same result as the prevIoUs one. Thereason to include it is to point out that some connection string keywords havemany equivalents.

Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;


Trusted Connection

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=sspI;

 

Trusted Connection alternative Syntax

This connection string produce the same result as the prevIoUs one. Thereason to include it is to point out that some connection string keywords havemany equivalents.

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

 

 

Connecting to an sql Server instance

The Syntax of specifying the server instance in the value of the server keyis the same for all connection strings for sql Server.

Server=myServername\theInstancename;Database=myDataBase;Trusted_Connection=True;

 

Trusted Connection from a CE device

Often a windows CE device is not authenticated and logged in to a domain.To use sspI or trusted connection / authentication from a CE device,use thisconnection string.

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=sspI;User ID=myDomain\myUsername;Password=myPassword;

Note that this will only work on a CE device.

Read more about connecting to SQL Server from CE devices here

 

Connect via an IP address

Data Source=190.190.200.100,1433;Network library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

DBMSSOCN=TCP/IP. This is how to use TCP/IP instead of named Pipes. At theend of the Data Source is the port to use. 1433 is the default port for sqlServer.

How to define which network protocol to use

 

Enabling MARS (multiple active result sets)

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; MultipleActiveResultSets=true;

Use ADO.NET for MARS functionality. MARS is not supported in ADO.NET 1.0nor ADO.NET 1.1.

Streamline yourData Connections by Moving to MARS,by Laurence Moroney,DevX.com

 

Attach a database file on connect to a local sql Server Express instance

Server=.\sqlExpress;AttachDbfilename=c:\asd\qwe\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have alreadybeen attached,sql Server does not reattach it. It uses the attached databaseas the default for the connection.

 

Attach a database file,located in the data directory,on connect to alocal sql Server Express instance

Server=.\sqlExpress;AttachDbfilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have alreadybeen attached,sql Server does not reattach it. It uses the attached databaseas the default for the connection.

 

Using an User Instance on a local sql Server Express instance

The User Instance functionality creates a new sql Server instance on thefly during connect. This works only on a local sql Server instance and onlywhen connecting using windows authentication over local named pipes. Thepurpose is to be able to create a full rights sql Server instance to a userwith limited administrative rights on the computer.

Data Source=.\sqlExpress;Integrated Security=true; AttachDbfilename=|DataDirectory|\mydb.mdf;User Instance=true;

To use the User Instance functionality you need to enable it on the sqlServer. This is done by executing the following command: sp_configure 'userinstances enabled','1'. To disable the functionality execute sp_configure'user instances enabled','0'.

 

Database mirroring

If you connect with ADO.NET or the sql Native ClIEnt to a database that isbeing mirrored,your application can take advantage of the drivers ability toautomatically redirect connections when a database mirroring failover occurs.You must specify the initial principal server and database in the connectionstring and the failover partner server.

Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;Initial Catalog=myDataBase;Integrated Security=True;

There is ofcourse many other ways to write the connection string usingdatabase mirroring,this is just one example pointing out the failoverfunctionality. You can combine this with the other connection strings optionsavailable.

 

Asynchronous processing

A connection to sql Server that allows for the issuing of async requeststhrough ADO.NET objects.

Server=myServerAddress;Database=myDataBase;Integrated Security=True;Asynchronous Processing=True;

 

sql Server Native ClIEnt 10.0 olE DB ProvIDer

Type:    olEDB ProvIDer
Usage:  ProvIDer=sqlNCli10

Manufacturer:  Microsoft
More info about this provider »

Customize string
example values »

Standard security

ProvIDer=sqlNCli10;Server=myServerAddress;Database=myDataBase;UID=myUsername; Pwd=myPassword;

Are you using sql Server 2008 Express? Don't miss the server name SyntaxServername\sqlEXPRESS where you substitute Servername with the name of thecomputer where the sql Server 2008 Express installation resIDes.

 

Trusted connection

ProvIDer=sqlNCli10;Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;

Equivalent key-value pair: "Integrated Security=sspI" equals"Trusted_Connection=yes"

 

Connecting to an sql Server instance

The Syntax of specifying the server instance in the value of the server keyis the same for all connection strings for sql Server.

ProvIDer=sqlNCli10;Server=myServername\theInstancename;Database=myDataBase; Trusted_Connection=yes;

 

Prompt for username and password

This one is a bit tricky. First you need to set the connection object'sPrompt property to adPromptAlways. Then use the connection string to connect tothe database.

oConn.PropertIEs("Prompt") = adPromptAlways

oConn.Open "ProvIDer=sqlNCli10;Server=myServerAddress;DataBase=myDataBase;

 

Enabling MARS (multiple active result sets)

ProvIDer=sqlNCli10;Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;MarsConn=yes;

Equivalent key-value pair: "MultipleActiveResultSets=true" equals"MARS_Connection=yes"

Use ADO.NET for MARS functionality. MARS is not supported in ADO.NET 1.0 norADO.NET 1.1.

Using MARS with SQL Native Client,by Chris Lee

 

Encrypt data sent over network

ProvIDer=sqlNCli10;Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;Encrypt=yes;

 

Attach a database file on connect to a local sql Server Express instance

ProvIDer=sqlNCli10;Server=.\sqlExpress;AttachDbfilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have alreadybeen attached,on connect to alocal sql Server Express instance

ProvIDer=sqlNCli10;Server=.\sqlExpress;AttachDbfilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have alreadybeen attached,sql Server does not reattach it. It uses the attached databaseas the default for the connection.

 

Database mirroring

If you connect with ADO.NET or the sql Native ClIEnt to a database that isbeing mirrored,your application can take advantage of the drivers ability toautomatically redirect connections when a database mirroring failover occurs.You must specify the initial principal server and database in the connectionstring and the failover partner server.

ProvIDer=sqlNCli10;Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;Initial Catalog=myDataBase;Integrated Security=True;

There is ofcourse many other ways to write the connection string usingdatabase mirroring,this is just one example pointing out the failoverfunctionality. You can combine this with the other connection strings optionsavailable.

 

.NET Framework Data ProvIDer for olE DB

Type:    .NETFramework Wrapper Class library
Usage:  System.Data.oleDb.oleDbConnection

Manufacturer:  Microsoft
More info about this wrapper class library »

Customize string
example values »

BrIDging to sql Native ClIEnt olE DB

This is just one connection string sample for the wrapPing oleDbConnectionclass that calls the underlying olEDB provIDer. See respective olE DB provIDerfor more connection strings to use with this class.

ProvIDer=sqlNCli10;Server=myServerAddress;Database=myDataBase;UID=myUsername; Pwd=myPassword;

 

sql Server Native ClIEnt 10.0 ODBC Driver

Type:    ODBCDriver
Usage:  Driver={sql Server Native ClIEnt 10.0}

Manufacturer:  Microsoft
More info about this driver »

Customize string
example values »

Standard security

Driver={sql Server NativeClIEnt 10.0};Server=myServerAddress;Database=myDataBase;UID=myUsername;Pwd=myPassword;

Are you using sql Server 2008 Express? Don't miss the server name SyntaxServername\sqlEXPRESS where you substitute Servername with the name of thecomputer where the sql Server 2008 Express installation resIDes.

 

Trusted Connection

Driver={sql Server NativeClIEnt 10.0};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;

Equivalent key-value pair: "Integrated Security=sspI" equals"Trusted_Connection=yes"

 

Connecting to an sql Server instance

The Syntax of specifying the server instance in the value of the server keyis the same for all connection strings for sql Server.

Driver={sql Server NativeClIEnt 10.0};Server=myServername\theInstancename; Database=myDataBase;Trusted_Connection=yes;

 

Prompt for username and password

This one is a bit tricky. First you need to set the connection object'sPrompt property to adPromptAlways. Then use the connection string to connect tothe database.

oConn.PropertIEs("Prompt") = adPromptAlways

Driver={sql Server NativeClIEnt 10.0};Server=myServerAddress;Database=myDataBase;

 

Enabling MARS (multiple active result sets)

Driver={sql Server NativeClIEnt 10.0};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes; MARS_Connection=yes;

Equivalent key-value pair: "MultipleActiveResultSets=true" equals"MARS_Connection=yes"

Use ADO.NET for MARS functionality. MARS is not supported in ADO.NET 1.0 norADO.NET 1.1.

Using MARS with SQL Native Client,by Chris Lee

 

Encrypt data sent over network

Driver={sql Server NativeClIEnt 10.0};Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;Encrypt=yes;

 

Attach a database file on connect to a local sql Server Express instance

Driver={sql Server NativeClIEnt 10.0};Server=.\sqlExpress; AttachDbfilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have already beenattached,sql Server does not reattach it. It uses the attached database as thedefault for the connection.

 

Attach a database file,on connect to a localsql Server Express instance

Driver={sql Server NativeClIEnt 10.0};Server=.\sqlExpress;AttachDbfilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have alreadybeen attached,your application can take advantage of the drivers ability toautomatically redirect connections when a database mirroring failover occurs.You must specify the initial principal server and database in the connectionstring and the failover partner server.

Driver={sql Server NativeClIEnt 10.0};Server=myServerAddress;Failover_Partner=myMirrorServerAddress;Database=myDataBase; Trusted_Connection=yes;

There is ofcourse many other ways to write the connection string usingdatabase mirroring,this is just one example pointing out the failoverfunctionality. You can combine this with the other connection strings optionsavailable.

Please note if you are using TCP/IP (using the network library parameter) anddatabase mirroring,including port number in the address (formed asservername,portnumber) for booth the main server and the failover partner cansolve some reported issues.

 

.NET Framework Data ProvIDer for ODBC

Type:    .NETFramework Wrapper Class library
Usage:  System.Data.Odbc.OdbcConnection

Manufacturer:  Microsoft
More info about this wrapper class library »

Customize string
example values »

BrIDging to sql Native ClIEnt 10.0 ODBC Driver

This is just one connection string sample for the wrapPing OdbcConnectionclass that calls the underlying ODBC Driver. See respective ODBC driver formore connection strings to use with this class.

Driver={sql Server NativeClIEnt 10.0};Server=myServerAddress;Database=myDataBase;UID=myUsername;Pwd=myPassword;

 

sqlXML 4.0 olEDB ProvIDer

Type:    olEDB ProvIDer
Usage:  ProvIDer=sqlXMLolEDB.4.0;Data ProvIDer=provIDername

Manufacturer:  Microsoft
More info about this provider »

Customize string
example values »

Using sql Server Native ClIEnt provIDer

ProvIDer=sqlXMLolEDB.4.0;Data ProvIDer=sqlNCli10;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

ADO连接Sql Server 2008 Express方法总结

使用ADO连接微软sql Server数据库,根据连接的类型有多种连接字符串,并且有些字符串的效果是一样的。

目前已经经过VS2008测试成功的连接字符串说明如下:

(1)第一种:指定sql Server 2008 Express安装的计算机名称

“ProvIDer=sqlNCli10;Server=Hostname\\sqlEXPRESS;Database=DBname;UID=Username;Pwd=Password”

其中:

sqlNCli10也可以替换为sqlolEDB。

Hostname为安装了sql Server 2008 Express的计算机名称,\\sqlEXPRESS是安装sql Server 2008 Express的实例名称,数据库安装时将用sqlEXPRESS作为缺省的实例名称,如果指定了其它实例名,则需要做相应的替换。

DBname为要连接的数据库名称。

Username和Password分别为连接数据库的用户名和密码。

如果指定信任连接,则可以在最后增加字符串“;Integrated Security=sspI”或者“;Trusted_Connection=yes”。

(2)第二种:指定sql Server 2008 Express安装的计算机IP地址

直接将上面字符串中的Hostname替换为对应的IP地址(如192.168.1.5)即可,如果IP地址为127.0.0.1,则连接本地的sql Serve 2008且实例名为sqlEXPRESS的数据库服务器。需要特别注意的是,此种情况只在sql Server browser服务启动时有效。

需要注意的几点:

(1)可能由于版本为EXPRESS的缘故,在连接字符串中必须指定形式为Hostname\\实例名或者IPAddress\\实例名的形式,否则连接不成功,这可能区别于其它版本的数据库连接方式。

(2)如果要以指定IP地址的方式连接,并且在不指定连接端口的情况下,sql Server browser服务必须开启,否则连接失败。另外sql Native ClIEnt 10.0配置中的客户端协议必须启用TCP/IP,如下图所示。

sql Server网络配置中的sqlEXPRESS的协议中的TCP/IP也必须启用,如下图所示。

(3)sql Server的默认监听端口为1433,可以指定其它的监听端口,此时需要在连接字符串中指定要连接的端口。具体配置如下。

 如果需要连接非默认端口1433,则可以在指定连接主机时指定连接端口。

 Server=127.0.0.1\\sqlEXPRESS,1443

只要指定了连接端口,sql Server browser服务不需要开启。

总结

以上是内存溢出为你收集整理的sqlserver2008远程连接不了全部内容,希望文章能够帮你解决sqlserver2008远程连接不了所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1180453.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存