The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Suggested EntitySpaces Dynamic Configuration for DotNetNuke Use

Last post 01-21-2007, 7:42 AM by Scott.Schecter. 0 replies.
Sort Posts: Previous Next
  •  01-21-2007, 7:42 AM 10

    Suggested EntitySpaces Dynamic Configuration for DotNetNuke Use

    Since many module developers may be using EntitySpaces on any one DNN installation, all developers need to play nice when it comes to setting the default connection. Since a large portion of Developers will simply be using the DNN installation, SQL server, the only reasonable thing to do is use that as the default connection. If a developer needs another connection, they can still set it for their code, however it should not be set as the default connection in consideration of others. Here is an example routine to illustrate proper usage.

    Code:
    1    #region EntitySpaces Connection Logic
    2
    3 private void SetConnection()
    4 {
    5 if (esConfigSettings.ConnectionInfo.Default != "SiteSqlServer")
    6 {
    7 esConfigSettings ConnectionInfoSettings = esConfigSettings.ConnectionInfo;
    8 foreach (esConnectionElement connection in ConnectionInfoSettings.Connections)
    9 {
    10 //if there is a SiteSqlServer in es connections set it default
    11 if (connection.Name == "SiteSqlServer")
    12 {
    13 esConfigSettings.ConnectionInfo.Default = connection.Name;
    14 return;
    15 }
    16 }
    17
    18 //no SiteSqlServer found grab dnn cnn string and create
    19 string dnnConnection = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
    20
    21 // Manually register a connection
    22 esConnectionElement conn = new esConnectionElement();
    23 conn.ConnectionString = dnnConnection;
    24 conn.Name = "SiteSqlServer";
    25 conn.Provider = "EntitySpaces.SqlClientProvider";
    26 conn.ProviderClass = "DataProvider";
    27 conn.SqlAccessType = esSqlAccessType.DynamicSQL;
    28 conn.ProviderMetadataKey = "esDefault";
    29 conn.DatabaseVersion = "2005";
    30
    31 // Assign the Default Connection
    32 esConfigSettings.ConnectionInfo.Connections.Add(conn);
    33 esConfigSettings.ConnectionInfo.Default = "SiteSqlServer";
    34
    35 // Register the Loader
    36 esProviderFactory.Factory = new EntitySpaces.LoaderMT.esDataProviderFactory();
    37 }
    38 }
    39
    40 #endregion


    Code:
    1    Private Sub SetConnection()
    2 If esConfigSettings.ConnectionInfo.[Default] <> "SiteSqlServer" Then
    3 Dim
    ConnectionInfoSettings As esConfigSettings = esConfigSettings.ConnectionInfo
    4 For Each connection As esConnectionElement In ConnectionInfoSettings.Connections
    5 'if there is a SiteSqlServer in es connections set it default 6 If connection.Name = "SiteSqlServer" Then 7 esConfigSettings.ConnectionInfo.[Default] = connection.Name
    8 Return
    9 End If
    10 Next
    11
    12 'no SiteSqlServer found grab dnn cnn string and create 13 Dim dnnConnection As String = ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString
    14
    15 ' Manually register a connection 16 Dim conn As New esConnectionElement()
    17 conn.ConnectionString = dnnConnection
    18 conn.Name = "SiteSqlServer" 19 conn.Provider = "EntitySpaces.SqlClientProvider" 20 conn.ProviderClass = "DataProvider" 21 conn.SqlAccessType = esSqlAccessType.DynamicSQL
    22 conn.ProviderMetadataKey = "esDefault" 23 conn.DatabaseVersion = "2005" 24
    25 ' Assign the Default Connection 26 esConfigSettings.ConnectionInfo.Connections.Add(conn)
    27 esConfigSettings.ConnectionInfo.[Default] = "SiteSqlServer" 28
    29 ' Register the Loader 30 esProviderFactory.Factory = New EntitySpaces.LoaderMT.esDataProviderFactory()
    31 End If
    32 End Sub
    33


    Regards,

    Scott Schecter
    EntitySpaces | My Site
    Filed under:
View as RSS news feed in XML