Dynamicweb 8 Documentation
IsAccess Property
Example 

Returns true if the solution is running on Access database. Return false if running on SQL-Server.
Syntax
'Declaration
 
Public Shared ReadOnly Property IsAccess As Boolean
public static bool IsAccess {get;}

Property Value

true or false
Remarks
Based on the database type set up for the particular solution in /Files/GlobalSettings.aspx in /Globalsettings/System/Database/Type node. Node must have a value of "ms_access" for this method to return true.
Example
Full database exampleFull database example
using System.Data;

namespace Dynamicweb.Examples.CSharp
{
    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("Access.mdb"))
            {
                //Do stuff witht the connection
            }

            //Check the database type and change the connection object to the database specific type returned.
            if (Database.IsAccess)
            {
                var con = (System.Data.OleDb.OleDbConnection)Database.CreateConnection();
            }
            else
            {
                var con = (System.Data.SqlClient.SqlConnection)Database.CreateConnection();
            }
        }
    }

}
Public Class DatabaseCreateConnection
    Public Sub ConnectToDatabase()

        'Create a connection to default database
        Using myConnection As IDbConnection = Database.CreateConnection()
            'Create a command object from the connection 
            Using myCommand As System.Data.IDbCommand = myConnection.CreateCommand
                'Create a DataAdapter
                Dim daAdapter As IDbDataAdapter = Database.CreateAdapter()

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

                'Fill a dataset
                Dim myDataSet As DataSet = New DataSet
                daAdapter.Fill(myDataSet)
            End Using
        End Using

        'Create a connection to another database in /Database folder when running Access
        Using myConnection As IDbConnection = Database.CreateConnection("Access.mdb")
            'Do stuff witht the connection
        End Using

        'Check the database type and change the connection object to the database specific type returned.
        If Database.IsAccess Then
            Dim con As OleDb.OleDbConnection = DirectCast(Database.CreateConnection(), OleDb.OleDbConnection)
        Else
            Dim con As SqlClient.SqlConnection = DirectCast(Database.CreateConnection(), SqlClient.SqlConnection)
        End If
    End Sub
End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Database Class
Database Members

Send Feedback