ASP.NET 连接 SQL Server 2000, 7.0 数据库

ODBC


提示输入用户名密码的方式

你必须先设置连接对象的提示属性为"adPromptAlways",然后再使用链接字串链接到数据库。

oConn.Properties("Prompt") = adPromptAlways Driver={SQL Server};Server=myServerAddress;Database=myDataBase;

复制代码

信任连接方式

Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes;

复制代码

标准连接方式

Driver={SQL Server}; Server=myServerAddress; Database=myDataBase; Uid=myUsername; Pwd=myPassword;

复制代码

OLE DB, OleDbConnection (.NET)


Disable connection pooling

This one is usefull when receving errors "sp_setapprole was not invoked correctly." (7.0) or "General network error. Check your network documentation" (2000) when connecting using an application role enabled connection. Application pooling (or OLE DB resource pooling) is on by default. Disabling it can help on this error.

Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;OLE DB Services=-2;

复制代码

Connect via an IP address

Provider=sqloledb;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 the end of the Data Source is the port to use. 1433 is the default port for SQL Server.

提示输入用户名密码的方式

首先你需要设置连接对象的Provider属性为"sqloledb"。然后再设置连接对象的Prompt属性为"adPromptAlways"。然后使用连接字符串连接到数据库。

oConn.Provider = "sqloledb"

复制代码

连接 SQL Server 实例

在服务器对象构造函数中提供 SQL Server 实例名称

Provider=sqloledb;Data Source=myServerName\theInstanceName;Initial Catalog=myDataBase;Integrated Security=SSPI;

复制代码

信任连接方式

Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

复制代码

使用“服务器\数据库实例”作为数据源连接到指定的数据库。注意多个SQL Server实例功能只适用于SQL Server 2000及更高级的版本。

标准连接方式

Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

复制代码

SqlConnection (.NET)


SQLXMLOLEDB