SQL Native Client ODBC Driver
学S3网N1页63网(http://www.xwangye.com)
标准安全连接
以下是语法格式:
Driver=
{SQL Native Client};
Server=
myServerAddress;
Database=
myDataBase;
Uid=
myUsername;
Pwd=
myPassword;
|
学S3网N1页63网(http://www.xwangye.com)
信任连接
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Driver=
{SQL Native Client};
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
等效的参数对:"Integrated Security=SSPI"与"Trusted_Connection=yes" 效果相同。
学S3网N1页63网(http://www.xwangye.com)
连接到一个SQL Server 实例
学S3网N1页63网(http://www.xwangye.com)
这个指明Sql Server 实例的语法中的server参数的值对所有连接Sql Server的字符串相同。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Driver=
{SQL Native Client};
Server=
myServerName/theInstanceName;
Database=
myDataBase;
Trusted_Connection=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
提示用户名和密码
学S3网N1页63网(http://www.xwangye.com)
这个有点麻烦。首先你要设置连接对象的Prompt属性为adPromptAlways,然后用连接字符串连接数据库。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
oConn.Properties("Prompt") = adPromptAlways
Driver= {SQL Native Client}; Server= myServerAddress; Database= myDataBase; |
学S3网N1页63网(http://www.xwangye.com)
允许多个结果集(Enable Mars (multiple active result sets))
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Driver=
{SQL Native Client};
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
yes;
MARS_Connection=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
等效的参数对:"MultipleActiveResultSets=true"与"MARS_Connection=yes" 效果相同。使用Mars功能需要ADO.NET2.0。ADO.NET1.0和1.1不支持此功能。
学S3网N1页63网(http://www.xwangye.com)
网络加密传输数据
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Driver=
{SQL Native Client};
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
yes;
Encrypt=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
在一个到本地SQL Server Express 实例的连接上附加数据库文件
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Driver=
{SQL Native Client};
Server=
./SQLExpress;
AttachDbFilename=
c:/asd/qwe/mydbfile.mdf;
Database=
dbname;
Trusted_Connection=
Yes;
|
学S3网N1页63网(http://www.xwangye.com)
为什么要带上Database参数呢?因为如果有同名的数据库已经被附加上啦,SQL Server将不会重新附加该数据库。他将使用原数据库作为要连接的对象。
学S3网N1页63网(http://www.xwangye.com)
在一个到本地SQL Server Express 实例的连接上附加数据库文件(数据文件在数据目录中。)
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Driver=
{SQL Native Client};
Server=
./SQLExpress;
AttachDbFilename=
|DataDirectory|mydbfile.mdf;
Database=
dbname;
Trusted_Connection=
Yes;
|
学S3网N1页63网(http://www.xwangye.com)
为什么要带上Database参数呢?因为如果有同名的数据库已经被附加上啦,SQL Server将不会重新附加该数据库。他将使用原数据库作为要连接的对象。
学S3网N1页63网(http://www.xwangye.com)
数据库镜像
学S3网N1页63网(http://www.xwangye.com)
如果你用Ado.Net或着SQL Native Client 连接到一个镜像的数据库,当一个数据库镜像出错时,你的应用程序应该提供自动切换连接的功能。那么,你应该在连接字符串中指明原始数据库名和镜像数据库名。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Data Source=
myServerAddress;
Failover Partner=
myMirrorServer;
Initial Catalog=
myDataBase;
Integrated Security=
True;
|
学S3网N1页63网(http://www.xwangye.com)
当然还有很多连接数据库镜像的连接字符串的写法。这只是一个例子指明 failover功能。你还可以指明其他的连接字符串属性参数。
学S3网N1页63网(http://www.xwangye.com)
学S3网N1页63网(http://www.xwangye.com)
SQL Native Client OLE DB Provider
学S3网N1页63网(http://www.xwangye.com)
标准安全连接
以下是语法格式:
Provider=
SQLNCLI;
Server=
myServerAddress;
Database=
myDataBase;
Uid=
myUsername;
Pwd=
myPassword;
|
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Provider=
SQLNCLI;
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
等效的参数对:"Integrated Security=SSPI"与"Trusted_Connection=yes" 效果相同。
学S3网N1页63网(http://www.xwangye.com)
连接到一个SQL Server 实例
学S3网N1页63网(http://www.xwangye.com)
这个指名Sql Server 实例的语法中的server参数的值对所有连接Sql Server的字符串相同。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Provider=
SQLNCLI;
Server=
myServerName/theInstanceName;
Database=
myDataBase;
Trusted_Connection=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
提示用户名和密码
学S3网N1页63网(http://www.xwangye.com)
这个有点麻烦。首先你要设置连接对象的Prompt属性为adPromptAlways,然后用连接字符串连接数据库。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Provider= SQLNCLI; Server= myServerAddress; DataBase= myDataBase; |
学S3网N1页63网(http://www.xwangye.com)
允许多个结果集(Enable Mars (multiple active result sets))
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Provider=
SQLNCLI;
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
yes;
MarsConn=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
等效的参数对:"MultipleActiveResultSets=true"与"MARS_Connection=yes" 效果相同。使用Mars功能需要ADO.NET2.0。ADO.NET1.0和1.1不支持此功能。
学S3网N1页63网(http://www.xwangye.com)
网络加密传输数据
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Provider=
SQLNCLI;
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
yes;
Encrypt=
yes;
|
学S3网N1页63网(http://www.xwangye.com)
在一个到本地SQL Server Express 实例的连接上附加数据库文件
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Provider=
SQLNCLI;
Server=
./SQLExpress;
AttachDbFilename=
c:/asd/qwe/mydbfile.mdf;
Database=
dbname;
Trusted_Connection=
Yes;
|
学S3网N1页63网(http://www.xwangye.com)
为什么要带上Database参数呢?因为如果有同名的数据库已经被附加上啦,SQL Server将不会重新附加该数据库。他将使用原数据库作为要连接的对象。
学S3网N1页63网(http://www.xwangye.com)
在一个到本地SQL Server Express 实例的连接上附加数据库文件(数据文件在数据目录中。)
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Provider=
SQLNCLI;
Server=
./SQLExpress;
AttachDbFilename=
|DataDirectory|mydbfile.mdf;
Database=
dbname;
Trusted_Connection=
Yes;
|
学S3网N1页63网(http://www.xwangye.com)
为什么要带上Database参数呢?因为如果有同名的数据库已经被附加上啦,SQL Server将不会重新附加该数据库。他将使用原数据库作为要连接的对象。
学S3网N1页63网(http://www.xwangye.com)
数据库镜像
学S3网N1页63网(http://www.xwangye.com)
如果你用Ado.Net或着SQL Native Client 连接到一个镜像的数据库,当一个数据库镜像出错时,你的应用程序应该提供自动切换连接的功能。那么,你应该在连接字符串中指明原始数据库名和镜像数据库名。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Data Source=
myServerAddress;
Failover Partner=
myMirrorServer;
Initial Catalog=
myDataBase;
Integrated Security=
True;
|
学S3网N1页63网(http://www.xwangye.com)
当然还有很多连接数据库镜像的连接字符串的写法。这只是一个例子指明 failover功能。你还可以指明其他的连接字符串属性参数。
学S3网N1页63网(http://www.xwangye.com)
SqlConnection (.NET)
学S3网N1页63网(http://www.xwangye.com)
标准安全连接
以下是语法格式:
Data Source=
myServerAddress;
Initial Catalog=
myDataBase;
User Id=
myUsername;
Password=
myPassword;
|
学S3网N1页63网(http://www.xwangye.com)
使用"服务器名/实例名"的格式作为Data Source来连接到一个Sql Server服务器上的一个实例。
学S3网N1页63网(http://www.xwangye.com)
你用过sql server 2005 Express么?不要忘记服务器的语法“Servername/SQLEXPRESS”(你要把Servername替换为装有sql server 2005 Express的计算机的名字)
学S3网N1页63网(http://www.xwangye.com)
标准连接的另一种语法
学S3网N1页63网(http://www.xwangye.com)
这个连接字符串和前一个的作用是一样的,只所以放到这里是为了说明有些连接参数带有相同的效果。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Server=
myServerAddress;
Database=
myDataBase;
User ID=
myUsername;
Password=
myPassword;
Trusted_Connection=
False;
|
学S3网N1页63网(http://www.xwangye.com)
信任的连接
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Data Source=
myServerAddress;
Initial Catalog=
myDataBase;
Integrated Security=
SSPI;
|
学S3网N1页63网(http://www.xwangye.com)
信任连接的另一种语法
学S3网N1页63网(http://www.xwangye.com)
这个连接字符串和前一个的作用是一样的,只所以放到这里是为了说明有些连接参数带有相同的效果。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
True;
|
学S3网N1页63网(http://www.xwangye.com)
连接到数据库实例
学S3网N1页63网(http://www.xwangye.com)
这个指名Sql Server 实例的语法中的server参数的值对所有连接Sql Server的字符串相同。
以下是语法格式:
Server=
myServerName/theInstanceName;
Database=
myDataBase;
Trusted_Connection=
True;
|
学S3网N1页63网(http://www.xwangye.com)
信任连接来至CE设备
学S3网N1页63网(http://www.xwangye.com)
通常CE设备是没有验证和登陆到域的。用SSPI或信任验证的连接要使用下面的连接字符串。
以下是语法格式:
Data Source=
myServerAddress;
Initial Catalog=
myDataBase;
Integrated Security=
SSPI;
User ID=
myDomain/myUsername;
Password=
myPassword;
|
学S3网N1页63网(http://www.xwangye.com)
注意:上面的语法只能用在CE设置上。
学S3网N1页63网(http://www.xwangye.com)
通过IP地址的连接
以下是语法格式:
Data Source=
190.190.200.100,1433;
Network Library=
DBMSSOCN;
Initial Catalog=
myDataBase;
User ID=
myUsername;
Password=
myPassword;
|
学S3网N1页63网(http://www.xwangye.com)
DBMSSOCN=TCP/IP.这是指明使用IP地址而不是命名管道来连接。Data Source的最后是端口。1433是数据库的默认端口。
学S3网N1页63网(http://www.xwangye.com)
允许多个结果集(Enable Mars (multiple active result sets))
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Server=
myServerAddress;
Database=
myDataBase;
Trusted_Connection=
True;
MultipleActiveResultSets=
true;
|
学S3网N1页63网(http://www.xwangye.com)
此功能只支持Ado.net 2.0.
学S3网N1页63网(http://www.xwangye.com)
在一个到本地SQL Server Express 实例的连接上附加数据库文件
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Server=
./SQLExpress;
AttachDbFilename=
c:/asd/qwe/mydbfile.mdf;
Database=
dbname;
Trusted_Connection=
Yes;
|
学S3网N1页63网(http://www.xwangye.com)
为什么要带上Database参数呢?因为如果有同名的数据库已经被附加上啦,SQL Server将不会重新附加该数据库。他将使用原数据库作为要连接的对象。
学S3网N1页63网(http://www.xwangye.com)
在一个到本地SQL Server Express 实例的连接上附加数据库文件(数据文件在数据目录中。)
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Server=
./SQLExpress;
AttachDbFilename=
|DataDirectory|mydbfile.mdf;
Database=
dbname;
Trusted_Connection=
Yes;
|
学S3网N1页63网(http://www.xwangye.com)
为什么要带上Database参数呢?因为如果有同名的数据库已经被附加上啦,SQL Server将不会重新附加该数据库。他将使用原数据库作为要连接的对象。
学S3网N1页63网(http://www.xwangye.com)
使用本机上的SQL Server Express 实例上的用户实例。
学S3网N1页63网(http://www.xwangye.com)
用户实例的连接创建了一个新的SQL Server 实例。此连接只能是在本地SQL Server 2005实例上并且是通过命名管的windows验证连接才有效。目的就是为了给用户创建一个完全权限的Sql Server 实例和有限的计算机管理员权限。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Data Source=
./SQLExpress;
Integrated Security=
true;
AttachDbFilename=
|DataDirectory|/mydb.mdf;
User Instance=
true;
|
学S3网N1页63网(http://www.xwangye.com)
要使用User Instance 功能,你要在sql server服务器上启用他。你可以通过执行“sp_configure 'user instances enabled', '1'”来启用,执行“sp_configure 'user instances enabled', '0'”来禁用。
学S3网N1页63网(http://www.xwangye.com)
数据库镜像
学S3网N1页63网(http://www.xwangye.com)
如果你用Ado.Net或着SQL Native Client 连接到一个镜像的数据库,当一个数据库镜像出错时,你的应用程序应该提供自动切换连接的功能。那么,你应该在连接字符串中指明原始数据库名和镜像数据库名。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Data Source=
myServerAddress;
Failover Partner=
myMirrorServer;
Initial Catalog=
myDataBase;
Integrated Security=
True;
|
学S3网N1页63网(http://www.xwangye.com)
当然还有很多连接数据库镜像的连接字符串的写法。这只是一个例子指明 failover功能。你还可以指明其他的连接字符串属性参数。
学S3网N1页63网(http://www.xwangye.com)
异步处理
学S3网N1页63网(http://www.xwangye.com)
SQL Server 2005允许通过Ado.net对象进行异步请求任务。
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
Server=
myServerAddress;
Database=
myDataBase;
Integrated Security=
True;
Asynchronous Processing=
True;
|
学S3网N1页63网(http://www.xwangye.com)
学S3网N1页63网(http://www.xwangye.com)
SQL Server 2005 specials
学S3网N1页63网(http://www.xwangye.com)
Context连接
学S3网N1页63网(http://www.xwangye.com)
Connecting to "self" from within your CLR stored prodedure/function. The context connection lets you execute Transact-SQL statements in the same context (connection) that your code was invoked in the first place.
学S3网N1页63网(http://www.xwangye.com)
以下是语法格式:
C#
using(SqlConnection connection = new SqlConnection("context connection=true")) { connection.Open(); // Use the connection } VB.Net Using connection as new SqlConnection("context connection=true") connection.Open() ' Use the connection End Using |