DatabaseProvider.CalculateConnectionString Method
Returns the calculated connection string for the database provider.
Namespace: Microsoft.Web.Management.DatabaseManager
Assembly: Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)
Syntax
'Declaration
Public MustOverride Function CalculateConnectionString ( _
arguments As ICollection(Of ConnectionArgument) _
) As String
'Usage
Dim instance As DatabaseProvider
Dim arguments As ICollection(Of ConnectionArgument)
Dim returnValue As String
returnValue = instance.CalculateConnectionString(arguments)
public abstract string CalculateConnectionString(
ICollection<ConnectionArgument> arguments
)
public:
virtual String^ CalculateConnectionString(
ICollection<ConnectionArgument^>^ arguments
) abstract
public abstract function CalculateConnectionString(
arguments : ICollection<ConnectionArgument>
) : String
Parameters
- arguments
Type: System.Collections.Generic.ICollection<ConnectionArgument>
The ICollection object that contains a collection of ConnectionArgument objects.
Return Value
Type: System.String
The calculated database connection string.
Remarks
Your provider must implement the CalculateConnectionString method in order to generate a connection string based on the arguments that your database provider requires.
Examples
The following code sample illustrates an example CalculateConnectionString method that returns the connection string for a Microsoft Access database provider.
Public Overrides Function CalculateConnectionString( _
ByVal arguments As System.Collections.Generic.ICollection( _
Of Microsoft.Web.Management.DatabaseManager.ConnectionArgument)) As String
Dim builder As OleDbConnectionStringBuilder = New OleDbConnectionStringBuilder
For Each argument As ConnectionArgument In arguments
Select Case (argument.Name)
Case "Provider"
builder.Provider = argument.Value
Case "Data Source"
builder.DataSource = argument.Value
Case "Jet OLEDB:Database Password"
builder.Add(argument.Name, argument.Value)
Case Else
Throw New ArgumentException(String.Format("The argument {0} is unexpected for this database provider!", argument.Name))
End Select
Next
Return builder.ToString
End Function
public override string CalculateConnectionString(
ICollection<ConnectionArgument> arguments )
{
OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder();
foreach (ConnectionArgument argument in arguments)
{
switch (argument.Name)
{
case "Provider":
builder.Provider = argument.Value;
break;
case "Data Source":
builder.DataSource = argument.Value;
break;
case "Jet OLEDB:Database Password":
builder.Add(argument.Name, argument.Value);
break;
default:
throw new ArgumentException(String.Format("The argument {0} is unexpected for this database provider!", argument.Name));
}
}
return builder.ToString();
}
Permissions
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.