[转]SQL Server 2005链接字符串

  1. 云栖社区>
  2. 博客>
  3. 正文

[转]SQL Server 2005链接字符串

toyohu 2008-05-16 15:49:00 浏览373
展开阅读全文
资料来自:http://www.mozlite.com/Article/sqlserver2005.aspx

以下列出的是SqlServer2005在编程过程中的链接字符串,可用于C++,VC++,ASP,PHP,.NET等等语言中。
 
SQL Native Client ODBC Driver
 
Standard Security
  1. Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword
Trusted Connection
  1. Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes
Connecting to a SQL Server Instance
  1. Driver={SQL Native Client};Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=yes
Prompt UserName and Password
  1. oConn.Properties("Prompt") = adPromptAlways  
  2.   
  3. Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase
Enabling MARS(multiple active results sets)
  1. Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MARS_Connection=yes
Encrypt data sent over network
  1. Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes
Attach a database file on connect to a local SQL Server Express Instance
  1. Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes
Attach a database file, located in the data directory, on connect to a local SQL Server Express Instance
  1. Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes
Database Mirroring
  1. Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;  
SQL Native Client OLE DB Provider
 
Standard Security
  1. Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword
Trusted Connection
  1. Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes
Connecting to a SQL Server Instance
  1. Provider=SQLNCLI;Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=yes
Prompt for username and password
  1. oConn.Properties("Prompt") = adPromptAlways  
  2.   
  3. oConn.Open "Provider=SQLNCLI;Server=myServerAddress;DataBase=myDataBase
Enabling MARS(multiple active results sets)
  1. Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MarsConn=yes
Encrypt data sent over network
  1. Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes
Attach a database file on connect to a local SQL Server Express Instance
  1. Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes
Attach a database file,located in the data directory,on connect to a local SQL Server Express Instance
  1. Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes
Database Mirroring
  1. Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;  
SqlConnection (.NET)
 
Standard Security
  1. Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword
Standard Security alternative syntax
  1. Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False
Trusted Connection
  1. Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI
Trusted Connection alternative syntax
  1. Server=myServerAddress;Database=myDataBase;Trusted_Connection=True
Connect to a SQL Server Instance
  1. Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True
Trusted connection from a CE device
  1. Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword
Connect via IP address
  1. Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword
Enabling MARS(multiple active results sets)
  1. Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;MultipleActiveResultSets=true
Attach a database file on connect to a local SQL Server Express Instance
  1. Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes
Attach a database file,located in the data directory,on connect to a local SQL Server Express Instance
  1. Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes
Using an user instance on a local SQL Server Express instance
  1. Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true
Database Mirroring
  1. Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True
Asynchronous processing
  1. Server=myServerAddress;Database=myDataBase;Integrated Security=True;Asynchronous Processing=True;  
SQL Server 2005 specials [ context connection ]
 
C#代码
  1. using(SqlConnection connection = new SqlConnection("context connection=true"))  
  2.  {  
  3.      connection.Open();  
  4.      // Use the connection  
  5.  } 
Visual Basic代码
  1. Using connection as new SqlConnection("context connection=true")  
  2.      connection.Open()  
  3.      ' Use the connection  
  4.  End Using  

网友评论

登录后评论
0/500
评论
toyohu
+ 关注