DatabaseProvider.CalculateConnectionString Method

IIS 7.0

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)

public abstract string CalculateConnectionString(
	ICollection<ConnectionArgument> arguments
)

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.

Your provider must implement the CalculateConnectionString method in order to generate a connection string based on the arguments that your database provider requires.

The following code sample illustrates an example CalculateConnectionString method that returns the connection string for a Microsoft Access database provider.



        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();
        }



Show: