admin 管理员组文章数量: 1086019
2024年2月27日发(作者:计算机二级c语言设计)
连接字符串中常用的声明有:
服务器声明 Data Source、Server和Addr等。
数据库声明 Initial Catalog和DataBase等。
集成Windows账号的安全性声明 Integrated Security和Trusted_Connection等。
使用数据库账号的安全性声明 User ID和Password等。
对于访问数据库的账号来说,通常我们在一些参考资料上看到的字符串连接往往有如下写法:
复制代码 代码如下:
string ConnStr = "server = localhost;
user id = sa; password = xxx; database = northwind";
对于集成Windows安全性的账号来说,其连接字符串写法一般如下:
复制代码 代码如下:
string ConnStr = "server = localhost;
integrated security = sspi; database = northwind";
或string ConnStr = "server = localhost;
trusted_connection = yes; database = northwind";
使用Windows集成的安全性验证在访问数据库时具有很多优势:安全性更高、访问速度更快、减少重新设计安全架构的工作、可以硬编码连接字符串等,还是很值得使用的。
SQL Native Client ODBC Driver
标准安全连接
复制代码 代码如下:Driver={SQL Native
Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
您是否在使用SQL Server 2005 Express? 请在“Server”选项使用连接表达式“主机名称SQLEXPRESS”。
受信的连接
复制代码 代码如下:Driver={SQL Native
Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
"Integrated Security=SSPI" 与 "Trusted_Connection=yes" 是相同的。
连接到一个SQL Server实例
指定服务器实例的表达式和其他SQL Server的连接字符串相同。
Driver={SQL Native
Client};Server=myServerNametheInstanceName;Database=myDataBase;Trusted_Connection=yes;
指定用户名和密码
ties("Prompt") = adPromptAlways
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
使用MARS (multiple active result sets)
Driver={SQL Native
Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MARS_Connection=yes;
"MultipleActiveResultSets=true"与MARS_Connection=yes"是相同的。
使用 2.0作为MARS的模块。 MARS不支持 1.0和 1.1。
验证网络数据
Driver={SQL Native
Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;
使用附加本地数据库文件的方式连接到本地SQL Server Express实例
Driver={SQL Native Client};Server=.SQLExpress;AttachDbFilename=c:;
Database=dbname;Trusted_Connection=Yes;
为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。
使用附加本地数据文件夹中的数据库文件的方式连接到本地SQL Server Express实例
Driver={SQL Native
Client};Server=.SQLExpress;AttachDbFilename=|DataDirectory|;
Database=dbname;Trusted_Connection=Yes;
为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。
数据库镜像
Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial
Catalog=myDataBase;Integrated Security=True;
SQL Native Client OLE DB Provider
标准连接
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
您是否在使用SQL Server 2005 Express? 请在“Server”选项使用连接表达式“主机名称SQLEXPRESS”。
受信的连接
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
"Integrated Security=SSPI"与"Trusted_Connection=yes"相同
连接到SQL Server实例
指定服务器实例的表达式和其他SQL Server的连接字符串相同。
Provider=SQLNCLI;Server=myServerNametheInstanceName;Database=myDataBase;Trusted_Connection=yes;
使用帐号和密码
ties("Prompt") = adPromptAlways
"Provider=SQLNCLI;Server=myServerAddress;DataBase=myDataBase;
使用MARS (multiple active result sets)
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MarsConn=yes;
"MultipleActiveResultSets=true"和"MARS_Connection=yes"是相同的。
使用 2.0作为MARS的模块。 MARS不支持 1.0和 1.1。
验证网络数据
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;
使用附加本地数据库文件的方式连接到本地SQL Server Express实例
Provider=SQLNCLI;Server=.SQLExpress;AttachDbFilename=c:;
Database=dbname;Trusted_Connection=Yes;
为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。
使用附加本地数据文件夹中的数据库文件的方式连接到本地SQL Server Express实例
Provider=SQLNCLI;Server=.SQLExpress;AttachDbFilename=|DataDirectory|;
Database=dbname;Trusted_Connection=Yes;
为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。
数据库镜像
Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial
Catalog=myDataBase;Integrated Security=True;
SqlConnection (.NET)
标准连接
Data Source=myServerAddress;Initial Catalog=myDataBase;User
Id=myUsername;Password=myPassword;
使用serverNameinstanceName作为数据源可以指定SQL Server实例。
您是否在使用SQL Server 2005 Express? 请在“Server”选项使用连接表达式“主机名称SQLEXPRESS”。
Standard Security alternative syntax
Server=myServerAddress;Database=myDataBase;User
ID=myUsername;Password=myPassword;Trusted_Connection=False;
受信任的连接
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Trusted Connection alternative syntax
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
连接到一个SQL Server的实例
指定服务器实例的表达式和其他SQL Server的连接字符串相同。
Server=myServerNametheInstanceName;Database=myDataBase;Trusted_Connection=True;
来自WinCE设备的安全连接
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User
ID=myDomainmyUsername;Password=myPassword;
仅能用于CE设备。
带有IP地址的连接
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial
Catalog=myDataBase;User ID=myUsername;Password=myPassword;
使用MARS (multiple active result sets)
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;MultipleActiveResultSets=true;
使用 2.0作为MARS的模块。 MARS不支持 1.0和 1.1。
使用附加本地数据库文件的方式连接到本地SQL Server Express实例
Server=.SQLExpress;AttachDbFilename=c:;Database=dbname;Trusted_Connection=Yes;
为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。
使用附加本地数据文件夹中的数据库文件的方式连接到本地SQL Server Express实例
Server=.SQLExpress;AttachDbFilename=|DataDirectory|;
Database=dbname;Trusted_Connection=Yes;
为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。
使用在SQL Server Express实例上的用户实例
Data Source=.SQLExpress;Integrated
Security=true;AttachDbFilename=|DataDirectory|;User Instance=true;
数据库镜像
Data Source=myServerAddress;Failover
Catalog=myDataBase;Integrated Security=True;
Asynchronous processing
Server=myServerAddress;Database=myDataBase;Integrated
Processing=True;
详细出处参考:/article/
Partner=myMirrorServer;Initial
Security=True;Asynchronous
版权声明:本文标题:SQL Server连接字符串 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1709048103a536943.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论