The ADOConnection allows you to establish a connection through an OLE DB provider.
To use the managed providers that come with NGWS frameworks, you need to include the following namespaces:
The following code demonstrates creating and opening a connection to a SQL Server Database:
[VB]
Dim connectionString As String = _ "server=localhost;uid=sa;pwd=;database=northwind" Dim myConnection As SQLConnection = New SQLConnection(connectionString) myConnection.Open()
[C#]
String connectionString = "server=localhost;uid=sa;pwd=;database=northwind"; SQLConnection myConnection = new SQLConnection(connectionString); MyConnection.Open();
[VB]
Dim connectionString As String = "Provider= SQLOLEDB.1; Data " & _ "Source=localhost; uid=sa; pwd=; Initial Catalog=northwind;" Dim myConnection As ADOConnection = New ADOConnection(connectionString) myConnection.Open()
[C#
String connectionString = "Provider= SQLOLEDB.1; Data Source=localhost; uid=sa; pwd=; Initial Catalog=northwind;"; ADOConnection myConnection = new ADOConnection(connectionString); MyConnection.Open();
The ADO and SQL Connection objects provide many of the properties that you are accustomed to with ADO.
For the ADO Managed Provider, the connection string format is identical to the connection string format used in ADO.
The SQL Managed Provider supports a connection string format that is a similar to the ADO connection string format. The following table summarizes the connection-string keywords supported by the SQLConnection object:
Name | Synonyms | Default | Description |
---|---|---|---|
App | "Application Name" | no default | Name of the application |
AttachDBFilename | "extended properties", "Initial File Name" | no default | name of the primary file (include the full path name) of an attachable database. You must also specify the database name with the 'database' keyword. |
Timeout | "Connection Timeout" | 15 | Length of time, in seconds, spent waiting to connect to the server before abandoning the attempt. |
Database | "Initial Catalog" | no default | Database name (initial catalog) |
Isolation Level | <none> | ReadCommitted | The transaction isolation level for the connection. Can be one of the following strings:
ReadCommitted ReadUncommitted RepeatableRead Serializable |
Language | "Current Language" | no default | SQL Server Language record name |
Network | "Network Library", "Net" | 'dbmssocn' | Net-library used to establish a connection to a SQL Server in the organization. Valid values are:
dbmssocn dbnmpntw dbmsrpcn dbmsvinn dbmsadsn dbmsspxn Note that the corresponding network library dll must be installed on the system. |
Password | "Pwd" | no default | SQL Server login password |
Server | "Data Source", "Address", "Addr", "Network Address" | no default | Name or network address of a SQL Server in the organization |
Trusted_Connection | "Integrated Security" | 'no' | Recognized values are 'yes' or 'no'. The value 'sspi' is also supported and equivalent to 'yes'. |
Uid | "User id" | no default | SQL Server login record name |
Wsid | "Workstation Id" | Current computer name. | Workstation identifier |
PersistSecurityInfo | "Persist Security Info" | 'no' | When equal to 'no', security-sensitive information such as the password is not returned as part of the connection string or from the corresponding property.
Note that this property cannot be changed while the connection is opened. An invalid operation exception will be thrown if this is attempted. The value of this property may be changed on a closed connection, but the previously set password cannot be retrieved if this property had been set to 'no'. However, the password may be set and then retrieved, until the connection is reopened. |