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