Table of Contents

Interface IDatabaseConnectionProvider

Namespace
Dynamicweb.Data
Assembly
Dynamicweb.Core.dll

Represents the database connection interface for the provider for replace the logic of creating database connections and data adapters to the Dynamicweb database.

public interface IDatabaseConnectionProvider

Remarks

You should not implement this interface directly. Inherit the DatabaseConnectionProvider instead.

Methods

CreateAdapter()

Creates a DataAdapter based on the database type of the solution.

IDbDataAdapter CreateAdapter()

Returns

IDbDataAdapter

A SqlDataAdapter

Examples

using System.Data;

namespace Dynamicweb.Data.Examples
{
    public class DatabaseCreateConnection
    {

        public void ConnectToDatabase()
        {
            //Create a connection to default database
            using (var myConnection = Database.CreateConnection())
            {
                //Create a command object from the connection 
                using (var myCommand = myConnection.CreateCommand())
                {
                    //Create a DataAdapter
                    var daAdapter = Database.CreateAdapter();

                    //Prepare command object
                    myCommand.CommandText = "SELECT TOP 1 * FROM Page";
                    daAdapter.SelectCommand = myCommand;

                    //Fill a dataset
                    var myDataSet = new DataSet();
                    daAdapter.Fill(myDataSet);
                }
            }

            //Create a connection to another database in /Database folder when running Access
            using (var myConnection = Database.CreateConnection())
            {
                //Do stuff witht the connection
            }

			var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
		}
    }
}

CreateConnection()

Creates and opens a database connection to the specified database.

IDbConnection CreateConnection()

Returns

IDbConnection

A Database Connection (a IDbConnection object). The connection is connected to the SQL Server database specified in database setup (/Files/GlobalSettings.aspx).

Examples

using System.Data;

namespace Dynamicweb.Data.Examples
{
    public class DatabaseCreateConnection
    {

        public void ConnectToDatabase()
        {
            //Create a connection to default database
            using (var myConnection = Database.CreateConnection())
            {
                //Create a command object from the connection 
                using (var myCommand = myConnection.CreateCommand())
                {
                    //Create a DataAdapter
                    var daAdapter = Database.CreateAdapter();

                    //Prepare command object
                    myCommand.CommandText = "SELECT TOP 1 * FROM Page";
                    daAdapter.SelectCommand = myCommand;

                    //Fill a dataset
                    var myDataSet = new DataSet();
                    daAdapter.Fill(myDataSet);
                }
            }

            //Create a connection to another database in /Database folder when running Access
            using (var myConnection = Database.CreateConnection())
            {
                //Do stuff witht the connection
            }

			var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
		}
    }
}

Remarks

The returned IDbConnection instance has to be a SqlConnection.

To top