Database.OpenConnectionString Method (String, String)

Opens a connection to a database using a connection string and the specified provider.

Namespace:  WebMatrix.Data
Assembly:  WebMatrix.Data (in WebMatrix.Data.dll)

Syntax

'Declaration
Public Shared Function OpenConnectionString ( _
    connectionString As String, _
    providerName As String _
) As Database
'Usage
Dim connectionString As String 
Dim providerName As String 
Dim returnValue As Database 

returnValue = Database.OpenConnectionString(connectionString, _
    providerName)
public static Database OpenConnectionString(
    string connectionString,
    string providerName
)
public:
static Database^ OpenConnectionString(
    String^ connectionString, 
    String^ providerName
)
static member OpenConnectionString : 
        connectionString:string * 
        providerName:string -> Database
public static function OpenConnectionString(
    connectionString : String, 
    providerName : String
) : Database

Parameters

  • connectionString
    Type: System.String
    The connection string that contains information that is used to connect to a database.
  • providerName
    Type: System.String
    (Optional) The name of the .NET Framework data provider to use to connect to the data source.

Return Value

Type: WebMatrix.Data.Database
The database instance.

Exceptions

Exception Condition
ArgumentException

connectionString is null reference (Nothing in Visual Basic) or empty.

Remarks

The OpenConnectionString method differs from the Open method, which uses the name of a connection string that is stored in the Web.config file.

You might use the OpenConnectionString method when a connection string is programmatically generated or is provided by the user.

See Also

Reference

Database Class

OpenConnectionString Overload

WebMatrix.Data Namespace