[轉]SQLServer2005連結字串

toyohu發表於2008-05-16
資料來自: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 heInstanceName;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:asdqwemydbfile.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 heInstanceName;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:asdqwemydbfile.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 heInstanceName;Database=myDataBase;Trusted_Connection=True
Trusted connection from a CE device
  1. Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomainmyUsername;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:asdqwemydbfile.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  


相關文章