Вы находитесь на странице: 1из 15

Connection strings for SQL Server 2005

This table shows all connection string properties for the ADO.NET SqlConnection object. Most of
the properties are also used in ADO. Using this table will give you a better understanding of the options
available.
The Properties
Some of the keywords have several equivalents. For those, each variant is specified on its own line
separated with "-or-".

Name Default Description


The name of the application, or '.Net SqlClient Data Provider' if no
Application Name
applicationname is provided.
When true, enables asynchronous operation support. Recognized
Async 'false'
values are true, false, yes, and no.
The name of the primary database file, including the full path
name of an attachable database. AttachDBFilename is only
supported for primary data files with an .mdf extension. The
attachment will fail if the primary data file is read-only. The path
may be absolute or relative by using the DataDirectory substitution
string. If DataDirectory is used, the database file must exist within
a subdirectory of the directory pointed to by the substitution string.
AttachDBFilename
-or- Note that remote servers, HTTP, and UNC
extended properties (\\server\sharename\folder\) path names are not supported.
-or-
Initial File Name The database name must be specified with the keyword 'database'
(or one of its aliases) as in the following: "AttachDbFileName=|
DataDirectory|\data\YourDB.mdf;integrated
security=true;database=YourDatabase". An error will be generated
if a log file exists in the same directory as the data file and the
'database' keyword is used when attaching the primary data file. In
this case, remove the log file. Once the database is attached, a new
log file will be automatically generated based on the physical path.
Connect Timeout
The length of time (in seconds) to wait for a connection to the
-or- 15
server before terminating the attempt and generating an error.
Connection Timeout
When a connection is returned to the pool, its creation time is
compared with the current time, and the connection is destroyed if
that time span (in seconds) exceeds the value specified by
Connection Lifetime 0 Connection Lifetime. This is useful in clustered configurations to
force load balancing between a running server and a server just
brought online. A value of zero (0) causes pooled connections to
have the maximum connection timeout.
Context Connection 'false' true if an in-process connection to SQL Server should be made.
Connection Reset 'true' Determines whether the database connection is reset when being
Name Default Description
removed from the pool. Setting to 'false' avoids making an
additional server round-trip when obtaining a connection, but the
programmer must be aware that the connection state is not being
reset.
Current Language The SQL Server Language record name.
The name or network address of the instance of SQL Server to
which to connect. The port number can be specified after the
Data Source
server name: server=tcp:servername, portnumber. When
-or-
specifying a local instance, always use (local). To force a protocol,
Server
add one of the following prefixes: np:(local), tcp:(local), lpc:
-or-
(local)
Address
-or-
ADO.NET 2.0 does not support asynchronous commands over
Addr
shared memory for SQL Server 2000 or earlier. However, you can
-or-
force the use of TCP instead of shared memory, either by prefixing
Network Address
tcp: to the server name in the connection string, or by using
localhost.
When true, SQL Server uses SSL encryption for all data sent
Encrypt 'false' between the client and server if the server has a certificate
installed. Recognized values are true, false, yes, and no.
When true, the pooler automatically enlists the connection in the
Enlist 'true' creation thread's current transaction context. Recognized values
are true, false, yes, and no.
The name of the failover partner server where database mirroring
Failover Partner N/A is configured. The Failover Partner keyword is not supported by
.NET Framework version 1.0 or 1.1.
Initial Catalog
-or- The name of the database.
Database
The minimum time, in seconds, for the connection to live in the
Load Balance Timeout 0
connection pool before being destroyed.
When true, an application can maintain multiple active result sets
(MARS). When false, an application must process or cancel all
MultipleActiveResultSets 'false' result sets from one batch before it can execute any other batch on
that connection. Recognized values are true and false. The
keyword is not supported by .NET Framework version 1.0 or 1.1.
Integrated Security Whether the connection is to be a secure connection or not.
-or- 'false' Recognized values are 'true', 'false', and 'sspi', which is equivalent
Trusted_Connection to 'true'.
Max Pool Size 100 The maximum number of connections allowed in the pool.
Min Pool Size 0 The minimum number of connections allowed in the pool.
Name Default Description
The network library used to establish a connection to an instance
of SQL Server. Supported values include dbnmpntw (Named
Pipes), dbmsrpcn (Multiprotocol, Windows RPC), dbmsadsn
(Apple Talk), dbmsgnet (VIA), dbmslpcn (Shared Memory, local
Network Library
machine only) and dbmsspxn (IPX/SPX), dbmssocn (TCP/IP) and
-or- 'dbmssocn'
Dbmsvinn (Banyan Vines).
Net
The corresponding network DLL must be installed on the system
to which you connect. If you do not specify a network and you use
a local server (for example, "." or "(local)"), shared memory is
used.
Size in bytes of the network packets used to communicate with an
Packet Size 8192
instance of SQL Server.
Password
The password for the SQL Server account logging on. Not used
-or-
with (the strongly recommended) 'Integrated Security=true' option.
Pwd
When set to 'false' (strongly recommended), security-sensitive
information, such as the password, is not returned as part of the
Persist Security Info 'false' connection if the connection is open or has ever been in an open
state. Resetting the connection string resets all connection string
values including the password.
When true, the SQLConnection object is drawn from the
Pooling 'true' appropriate pool, or if necessary, is created and added to the
appropriate pool. Recognized values are true, false, yes, and no.
Replication 'false' true if replication is supported using the connection.
Controls connection association with an enlisted
System.Transactions transaction. Possible values are:
Transaction Binding=Implicit Unbind;
Transaction Binding=Explicit Unbind;
Implicit Unbind causes the connection to detach from the
transaction when it ends. After detaching, additional requests on
the connection are performed in autocommit mode. The
System.Transactions.Transaction.Current property is not checked
Implicit
Transaction Binding when executing requests while the transaction is active. After the
Unbind
transaction has ended, additional requests are performed in
autocommit mode.
Explicit Unbind causes the connection to remain attached to the
transaction until the connection is closed or an explicit
SqlConnection.TransactionEnlist(null) is called. An
InvalidOperationException is thrown if Transaction.Current is not
the enlisted transaction or if the enlisted transaction is not active.

TrustServerCertificate 'false' When set to true, SSL is used to encrypt the channel when
bypassing walking the certificate chain to validate trust. If
TrustServerCertificate is set to true and Encrypt is set to false, the
Name Default Description
channel is not encrypted. Recognized values are true, false, yes,
and no.
A string value that indicates the type system the application
expects. Possible values are:
Type System Version=SQL Server 2000;
Type System Version=SQL Server 2005;
Type System Version=SQL Server 2008;
Type System Version=Latest;
When set to SQL Server 2000, the SQL Server 2000 type system is
used. The following conversions are performed when connecting
to a SQL Server 2005 instance:
Type System Version N/A XML to NTEXT
UDT to VARBINARY
VARCHAR(MAX), NVARCHAR(MAX) and
VARBINARY(MAX) to TEXT, NEXT and IMAGE respectively.
When set to SQL Server 2005, the SQL Server 2005 type system is
used. No conversions are made for the current version of
ADO.NET.
When set to Latest, the latest version than this client-server pair
can handle is used. This will automatically move forward as the
client and server components are upgraded.
User ID The SQL Server login account.
A value that indicates whether to redirect the connection from the
User Instance 'false' default SQL Server Express instance to a runtime-initiated
instance running under the account of the caller.
The local
Workstation ID computer The name of the workstation connecting to SQL Server.
name
Summary
There is no point in always defining each of these properties. Return to this sheet to look up definitions as
a way to ensure proper connections. Also use this as a reference to ensure that you have included every
property applicable to your specific situation.

Standard Security
Data Source=myServerAddress;Initial Catalog=myDataBase;User
Id=myUsername;Password=myPassword;
Use serverName\instanceName as Data Source to connect to a specific SQL Server instance.

Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS
where you substitute Servername with the name of the computer where the SQL Server 2005 Express
installation resides.

Standard Security alternative syntax


This connection string produce the same result as the previous one. The reason to include it is to point out
that some connection string keywords have many equivalents.
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


This connection string produce the same result as the previous one. The reason to include it is to point out
that some connection string keywords have many equivalents.
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

Connecting to an SQL Server instance


The syntax of specifying the server instance in the value of the server key is the same for all connection
strings for SQL Server.
Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;

Trusted Connection from a CE device


Often a Windows CE device is not authenticated and logged in to a domain. To use SSPI or trusted
connection / authentication from a CE device, use this connection string.
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User
ID=myDomain\myUsername;Password=myPassword;
Note that this will only work on a CE device.
More Information: http://msdn2.microsoft.com/en-us/library/aa275613%28SQL.80%29.aspx

Connect via an IP address


Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User
ID=myUsername;Password=myPassword;
DBMSSOCN=TCP/IP.
This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433
is the default port for SQL Server.
How to define which network protocol to use
http://www.connectionstrings.com/Articles/Show/define-sql-server-network-protocol

Enabling MARS (multiple active result sets)


Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
MultipleActiveResultSets=true;
Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
Streamline your Data Connections by Moving to MARS, by Laurence Moroney, DevX.com
http://www.devx.com/dbzone/Article/30132

Attach a database file on connect to a local SQL Server Express instance


Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

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;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

Using an User Instance on a local SQL Server Express instance


The User Instance functionality creates a new SQL Server instance on the fly during connect. This works
only on a local SQL Server 2005 instance and only when connecting using windows authentication over
local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with
limited administrative rights on the computer.
Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User
Instance=true;
To use the User Instance functionality you need to enable it on the SQL Server. This is done by executing
the following command: sp_configure 'user instances enabled', '1'. To disable the functionality execute
sp_configure 'user instances enabled', '0'.

Database mirroring
If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your
application can take advantage of the drivers ability to automatically redirect connections when a database
mirroring failover occurs. You must specify the initial principal server and database in the connection
string and the failover partner server.
Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;Initial
Catalog=myDataBase;Integrated Security=True;
There is ofcourse many other ways to write the connection string using database mirroring, this is just one
example pointing out the failover functionality. You can combine this with the other connection strings
options available.
Read more about database mirroring in this Microsoft TechNet article "Database Mirroring in SQL Server
2005"
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx

Asynchronous processing
A connection to SQL Server 2005 that allows for the issuing of async requests through ADO.NET objects.
Server=myServerAddress;Database=myDataBase;Integrated Security=True;Asynchronous
Processing=True;

SQL Native Client 9.0 OLE DB provider


Type: OLE DB Provider
Usage: Provider=SQLNCLI
Manufacturer: Microsoft
More info about this provider Customize string example values
http://www.connectionstrings.com/ConnectionStrings/Customize/sql-server-2005

Standard security
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS
where you substitute Servername with the name of the computer where the SQL Server 2005 Express
installation resides.

Trusted connection
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"

Connecting to an SQL Server instance


The syntax of specifying the server instance in the value of the server key is the same for all connection
strings for SQL Server.
Provider=SQLNCLI;Server=myServerName\theInstanceName;Database=myDataBase;
Trusted_Connection=yes;

Prompt for username and password


This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways.
Then use the connection string to connect to the database.
oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Provider=SQLNCLI;Server=myServerAddress;DataBase=myDataBase;

Enabling MARS (multiple active result sets)


Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;MARS
Connection=True;
Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
Using MARS with SQL Native Client, by Chris Lee
http://blogs.msdn.com/dataaccess/archive/2005/08/02/446894.aspx

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:\mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

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;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

Download the SQL Native Client here. The package contains booth the ODBC driver and the OLE DB
provider
http://download.microsoft.com/download/4/4/D/44DBDE61-B385-4FC2-A67D-
48053B8F9FAD/sqlncli.msi

Database mirroring
If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your
application can take advantage of the drivers ability to automatically redirect connections when a database
mirroring failover occurs. You must specify the initial principal server and database in the connection
string and the failover partner server.
Provider=SQLNCLI;Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;Initial
Catalog=myDataBase;Integrated Security=True;
There is ofcourse many other ways to write the connection string using database mirroring, this is just one
example pointing out the failover functionality. You can combine this with the other connection strings
options available.
Read more about database mirroring in this Microsoft TechNet article "Database Mirroring in SQL Server
2005"
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx

.NET Framework Data Provider for OLE DB


Type: .NET Framework Wrapper Class Library
Usage: System.Data.OleDb.OleDbConnection
Manufacturer: Microsoft
More info about this wrapper class library Customize string example values
http://www.connectionstrings.com/Providers/net-framework-data-provider-for-ole-db

Bridging to SQL Native Client OLE DB


This is just one connection string sample for the wrapping OleDbConnection class that calls the
underlying OLEDB provider. See respective OLE DB provider for more connection strings to use with
this class.
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;

SQL Server Native Client 10.0 OLE DB Provider


Type: OLE DB Provider
Usage: Provider=SQLNCLI10
Manufacturer: Microsoft
More info about this provider Customize string example values
http://www.connectionstrings.com/ConnectionStrings/Customize/sql-server-2005

Standard security
Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS
where you substitute Servername with the name of the computer where the SQL Server 2005 Express
installation resides.

Trusted connection
Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"

Connecting to an SQL Server instance


The syntax of specifying the server instance in the value of the server key is the same for all connection
strings for SQL Server.
Provider=SQLNCLI10;Server=myServerName\theInstanceName;Database=myDataBase;
Trusted_Connection=yes;

Prompt for username and password


This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways.
Then use the connection string to connect to the database.
oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Provider=SQLNCLI10;Server=myServerAddress;DataBase=myDataBase;

Enabling MARS (multiple active result sets)


Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;
Trusted_Connection=yes;MARS Connection=True;
Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
Using MARS with SQL Native Client, by Chris Lee
http://blogs.msdn.com/dataaccess/archive/2005/08/02/446894.aspx

Encrypt data sent over network


Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;
Trusted_Connection=yes;Encrypt=yes;

Attach a database file on connect to a local SQL Server Express instance


Provider=SQLNCLI10;Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
Provider=SQLNCLI10;Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.
Download the SQL Native Client here. The package contains booth the ODBC driver and the OLE DB
provider
http://download.microsoft.com/download/4/4/D/44DBDE61-B385-4FC2-A67D-
48053B8F9FAD/sqlncli.msi

Database mirroring
If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your
application can take advantage of the drivers ability to automatically redirect connections when a database
mirroring failover occurs. You must specify the initial principal server and database in the connection
string and the failover partner server.
Provider=SQLNCLI10;Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;Initial
Catalog=myDataBase;Integrated Security=True;
There is ofcourse many other ways to write the connection string using database mirroring, this is just one
example pointing out the failover functionality. You can combine this with the other connection strings
options available.
Read more about database mirroring in this Microsoft TechNet article "Database Mirroring in SQL Server
2005"
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
SQL Native Client 9.0 ODBC Driver
Type: ODBC Driver
Usage: Driver={SQL Native Client}
Manufacturer: Microsoft
More info about this driver Customize string example values
http://www.connectionstrings.com/ConnectionStrings/Customize/sql-server-2005

Standard security
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS
where you substitute Servername with the name of the computer where the SQL Server 2005 Express
installation resides.

Trusted Connection
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Trusted_Connection=yes;
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"

Connecting to an SQL Server instance


The syntax of specifying the server instance in the value of the server key is the same for all connection
strings for SQL Server.
Driver={SQL Native Client};Server=myServerName\theInstanceName;Database=myDataBase;
Trusted_Connection=yes;

Prompt for username and password


This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways.
Then use the connection string to connect to the database.
oConn.Properties("Prompt") = adPromptAlways

Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;

Enabling MARS (multiple active result sets)


Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Trusted_Connection=yes;MARS_Connection=yes;
Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
Using MARS with SQL Native Client, by Chris Lee
http://blogs.msdn.com/dataaccess/archive/2005/08/02/446894.aspx
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:\mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

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;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.
Download the SQL Native Client here. The package contains booth the ODBC driver and the OLE DB
provider
http://download.microsoft.com/download/4/4/D/44DBDE61-B385-4FC2-A67D-
48053B8F9FAD/sqlncli.msi

Database mirroring
If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your
application can take advantage of the drivers ability to automatically redirect connections when a database
mirroring failover occurs. You must specify the initial principal server and database in the connection
string and the failover partner server.
Driver={SQL Server Native Client
10.0};Server=myServerAddress;Failover_Partner=myMirrorServerAddress;Database=myDataBase;
Trusted_Connection=yes;
There is ofcourse many other ways to write the connection string using database mirroring, this is just one
example pointing out the failover functionality. You can combine this with the other connection strings
options available.

Please note if you are using TCP/IP (using the network library parameter) and database mirroring,
including port number in the address (formed as servername,portnumber) for booth the main server and
the failover partner can solve some reported issues.
Read more about database mirroring in this Microsoft TechNet article "Database Mirroring in SQL Server
2005"
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
SQL Server Native Client 10.0 ODBC Driver
Type: ODBC Driver
Usage: Driver={SQL Server Native Client 10.0}
Manufacturer: Microsoft
More info about this driver Customize string example values
http://www.connectionstrings.com/ConnectionStrings/Customize/sql-server-2005
Standard security
Driver={SQL Server Native Client
10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Trusted Connection
Driver={SQL Server Native Client
10.0};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"

Connecting to an SQL Server instance


The syntax of specifying the server instance in the value of the server key is the same for all connection
strings for SQL Server.
Driver={SQL Server Native Client 10.0};Server=myServerName\theInstanceName;
Database=myDataBase;Trusted_Connection=yes;

Prompt for username and password


This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways.
Then use the connection string to connect to the database.
oConn.Properties("Prompt") = adPromptAlways

Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;

Enabling MARS (multiple active result sets)


Driver={SQL Server Native Client
10.0};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
MARS_Connection=yes;
Use ADO.NET for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
Using MARS with SQL Native Client, by Chris Lee
http://blogs.msdn.com/dataaccess/archive/2005/08/02/446894.aspx

Encrypt data sent over network


Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;
Trusted_Connection=yes;Encrypt=yes;
Attach a database file on connect to a local SQL Server Express instance
Driver={SQL Server Native Client 10.0};Server=.\SQLExpress;
AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
Driver={SQL Server Native Client 10.0};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|
mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server
does not reattach it. It uses the attached database as the default for the connection.

Database mirroring
If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your
application can take advantage of the drivers ability to automatically redirect connections when a database
mirroring failover occurs. You must specify the initial principal server and database in the connection
string and the failover partner server.
Driver={SQL Server Native Client
10.0};Server=myServerAddress;Failover_Partner=myMirrorServerAddress;Database=myDataBase;
Trusted_Connection=yes;
There is ofcourse many other ways to write the connection string using database mirroring, this is just one
example pointing out the failover functionality. You can combine this with the other connection strings
options available.

Please note if you are using TCP/IP (using the network library parameter) and database mirroring,
including port number in the address (formed as servername,portnumber) for booth the main server and
the failover partner can solve some reported issues.
Read more about database mirroring in this Microsoft TechNet article "Database Mirroring in SQL Server
2005"
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx

.NET Framework Data Provider for ODBC


Type: .NET Framework Wrapper Class Library
Usage: System.Data.Odbc.OdbcConnection
Manufacturer: Microsoft
More info about this wrapper class library Customize string example values
http://www.connectionstrings.com/ConnectionStrings/Customize/sql-server-2005

Bridging to SQL Native Client 10.0 ODBC Driver


This is just one connection string sample for the wrapping OdbcConnection class that calls the underlying
ODBC Driver. See respective ODBC driver for more connection strings to use with this class.
Driver={SQL Server Native Client
10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
SQLXML 4.0 OLEDB Provider
Type: OLE DB Provider
Usage: Provider=SQLXMLOLEDB.4.0;Data Provider=providername
Manufacturer: Microsoft
More info about this provider Customize string example values
http://www.connectionstrings.com/Providers/sqlxml-4-0-oledb-provider

Using SQL Server Native Client provider


Provider=SQLXMLOLEDB.4.0;Data Provider=SQLNCLI;Data Source=myServerAddress;Initial
Catalog=myDataBase;User Id=myUsername;Password=myPassword;

Context Connection
Type: .NET Framework Class Library
Usage:
Manufacturer: Microsoft
More info about this class library Customize string example values
http://www.connectionstrings.com/ConnectionStrings/Customize/sql-server-2005

Context Connection
Connecting to "self" from within your CLR stored prodedure/function. The context connection lets you
execute Transact-SQL statements in the same context (connection) that your code was invoked in the first
place.
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

Вам также может понравиться