Standard Security
Standard Security alternative syntax
Trusted Connection
Trusted Connection alternative syntax
Connecting to an SQL Server instance
Trusted Connection from a CE device
Connect via an IP address
Enabling MARS (multiple active result sets)
Attach a database file on connect to a local SQL Server Express instance
Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
Using an User Instance on a local SQL Server Express instance
Database mirroring
Asynchronous processing
Standard security
Trusted connection
Connecting to an SQL Server instance
Prompt for username and password
Enabling MARS (multiple active result sets)
Encrypt data sent over network
Attach a database file on connect to a local SQL Server Express instance
Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
Database mirroring
Bridging to SQL Native Client OLE DB
Standard security
Trusted Connection
Connecting to an SQL Server instance
Prompt for username and password
Enabling MARS (multiple active result sets)
Encrypt data sent over network
Attach a database file on connect to a local SQL Server Express instance
Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
Database mirroring
Bridging to SQL Native Client 10.0 ODBC Driver
Using SQL Server Native Client provider
Context Connection
Data Source=SERVER-IP;Initial Catalog=DATABASE-NAME;User Id=USERNAME;Password=PASSWORD;
Server=SERVER-IP;Database=DATABASE-NAME;User ID=USERNAME;Password=PASSWORD;Trusted_Connection=F alse;
Data Source=SERVER-IP;Initial Catalog=DATABASE-NAME;Integrated Security=SSPI;
Server=SERVER-IP;Database=DATABASE-NAME;Trusted_Connection=True;
Connecting to an SQL Server instance
Server=myServerName\theInstanceName;Database=DATAB ASE-NAME;Trusted_Connection=True;
Data Source=SERVER-IP;Initial Catalog=DATABASE-NAME;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=DATABASE-NAME;User ID=USERNAME;Password=PASSWORD;
Server=SERVER-IP;Database=DATABASE-NAME;Trusted_Connection=True; MultipleActiveResultSets=true;
Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\my dbfile.mdf;Database=dbname; Trusted_Connection=Yes;
Server=.\SQLExpress;AttachDbFilename=|DataDirector y|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;
Data Source=SERVER-IP;Failover Partner=myMirrorServerAddress;Initial Catalog=DATABASE-NAME;Integrated Security=True;
Asynchronous processing
Server=SERVER-IP;Database=DATABASE-NAME;Integrated Security=True;Asynchronous Processing=True;
Provider=SQLNCLI10;Server=SERVER-IP;Database=DATABASE-NAME;Uid=USERNAME; Pwd=PASSWORD;
Provider=SQLNCLI10;Server=SERVER-IP;Database=DATABASE-NAME; Trusted_Connection=yes;
Provider=SQLNCLI10;Server=myServerName\theInstance Name;Database=DATABASE-NAME; Trusted_Connection=yes;
Prompt for username and password
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Provider=SQLNCLI10;Server=SERVER-IP;DataBase=DATABASE-NAME;
oConn.Open "Provider=SQLNCLI10;Server=SERVER-IP;DataBase=DATABASE-NAME;
Provider=SQLNCLI10;Server=SERVER-IP;Database=DATABASE-NAME; Trusted_Connection=yes;MARS Connection=True;
Provider=SQLNCLI10;Server=SERVER-IP;Database=DATABASE-NAME; Trusted_Connection=yes;Encrypt=yes;
Provider=SQLNCLI10;Server=.\SQLExpress;AttachDbFil ename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Trusted_Connection=Yes;
Provider=SQLNCLI10;Server=.\SQLExpress;AttachDbFil ename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
Provider=SQLNCLI10;Data Source=SERVER-IP;Failover Partner=myMirrorServerAddress;Initial Catalog=DATABASE-NAME;Integrated Security=True;
Provider=SQLNCLI10;Server=SERVER-IP;Database=DATABASE-NAME;Uid=USERNAME; Pwd=PASSWORD;
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Database=DATABASE-NAME;Uid=USERNAME;Pwd=PASSWORD;
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Database=DATABASE-NAME;Trusted_Connection=yes;
Driver={SQL Server Native Client 10.0};Server=myServerName\theInstanceName; Database=DATABASE-NAME;Trusted_Connection=yes;
Prompt for username and password
oConn.Properties("Prompt") = adPromptAlways
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Database=DATABASE-NAME;
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Database=DATABASE-NAME;
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Database=DATABASE-NAME;Trusted_Connection=yes; MARS_Connection=yes;
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Database=DATABASE-NAME; Trusted_Connection=yes;Encrypt=yes;
Driver={SQL Server Native Client 10.0};Server=.\SQLExpress; AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
Driver={SQL Server Native Client 10.0};Server=.\SQLExpress;AttachDbFilename=|DataDi rectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Failover_Partner=myMirrorServerAddress;Database =DATABASE-NAME; Trusted_Connection=yes;
Driver={SQL Server Native Client 10.0};Server=SERVER-IP;Database=DATABASE-NAME;Uid=USERNAME;Pwd=PASSWORD;
Provider=SQLXMLOLEDB.4.0;Data Provider=SQLNCLI10;Data Source=SERVER-IP;Initial Catalog=DATABASE-NAME;User Id=USERNAME;Password=PASSWORD;
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
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