Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDatabase accessDatabase access
Previous
 
Next
New Post
11/26/2010 6:29 AM
 
So if I add the following code in my class:

Private ProviderConfiguration As DotNetNuke.Framework.Providers.ProviderConfiguration = DotNetNuke.Framework.Providers.ProviderConfiguration.GetProviderConfiguration("data")
Private objProvider As DotNetNuke.Framework.Providers.Provider = CType(ProviderConfiguration.Providers(ProviderConfiguration.DefaultProvider), DotNetNuke.Framework.Providers.Provider)

Private Function GetConnectionString() As String
    Dim ConnectionString As String = Config.GetConnectionString()
    If ConnectionString = "" Then
        ' Use connection string specified in provider
        ConnectionString = objProvider.Attributes("connectionString")
    End If
    Return ConnectionString
End Function

Private Function GetDatabaseOwner() As String
    Dim DatabaseOwner = objProvider.Attributes("databaseOwner")
    If DatabaseOwner <> "" And (Not DatabaseOwner.EndsWith(".")) Then
        DatabaseOwner &= "."
    End If
    Return DatabaseOwner
End Function


And after that I change my functions to look like the one below:

Public Function SelectCategories(ByVal LanguageID As String) As DataTable
    Dim MyConnection As New System.Data.SqlClient.SqlConnection(GetConnectionString)
    MyConnection.Open()

    Dim MyCommand As New System.Data.SqlClient.SqlCommand
    MyCommand.Connection = MyConnection
    MyCommand.CommandType = System.Data.CommandType.Text
    MyCommand.CommandText = "SELECT CategoryID, CategoryName, CategoryParent FROM " & GetDatabaseOwner() & "Map_Categories WHERE LanguageID = @LanguageID"
    MyCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LanguageID", LanguageID))

    Dim MyDataAdapter As New SqlClient.SqlDataAdapter(MyCommand)
    Dim MyDataSet As New DataSet()
    MyDataAdapter.Fill(MyDataSet)
    MyConnection.Close()

    Return MyDataSet.Tables(0)
End Function


Is this better now?
 
New Post
11/26/2010 6:35 AM
 
Aristotelis

You added databaseOwner, but missed objectQulifier. You have to add it too.

Sergey
 
New Post
11/26/2010 6:44 AM
 
What is the objectQulifier? I know that in order to identify a database table you have to use the following structure for the name:

databaseOwner.tablename
 
New Post
11/26/2010 6:46 AM
 
Aristotelis

{objectQulifier} is the same prefix Lars told you about. It is in the same place of code where you have taken previous:

_objectQualifier = objProvider.Attributes["objectQualifier"];
if (_objectQualifier != "" & _objectQualifier.EndsWith("_") == false)
{
_objectQualifier += "_";
}

Sergey
 
New Post
11/26/2010 7:08 AM
 
My new version is the following:

        Private ProviderConfiguration As DotNetNuke.Framework.Providers.ProviderConfiguration = DotNetNuke.Framework.Providers.ProviderConfiguration.GetProviderConfiguration("data")
        Private objProvider As DotNetNuke.Framework.Providers.Provider = CType(ProviderConfiguration.Providers(ProviderConfiguration.DefaultProvider), DotNetNuke.Framework.Providers.Provider)

        Private Function GetConnectionString() As String
            Dim ConnectionString As String = Config.GetConnectionString()
            If ConnectionString = "" Then
                ' Use connection string specified in provider
                ConnectionString = objProvider.Attributes("connectionString")
            End If
            Return ConnectionString
        End Function

        Private Function GetDatabaseOwner() As String
            Dim DatabaseOwner = objProvider.Attributes("databaseOwner")
            If DatabaseOwner <> "" And (Not DatabaseOwner.EndsWith(".")) Then
                DatabaseOwner &= "."
            End If
            Return DatabaseOwner
        End Function

        Private Function GetObjectQualifier() As String
            Dim ObjectQualifier As String = objProvider.Attributes("objectQualifier")
            If ObjectQualifier <> "" And Not (ObjectQualifier.EndsWith("_")) Then
                ObjectQualifier &= "_"
            End If

            Return ObjectQualifier
        End Function

        Private Function GetFullyQualifiedName(ByVal name As String) As String
            Return GetDatabaseOwner() & GetObjectQualifier() & name
        End Function


And my function will have the following structure:

        Public Function SelectCategories(ByVal LanguageID As String) As DataTable
            Dim MyConnection As New System.Data.SqlClient.SqlConnection(GetConnectionString)
            MyConnection.Open()

            Dim MyCommand As New System.Data.SqlClient.SqlCommand
            MyCommand.Connection = MyConnection
            MyCommand.CommandType = System.Data.CommandType.Text
            MyCommand.CommandText = "SELECT CategoryID, CategoryName, CategoryParent FROM " & GetFullyQualifiedName("Map_Categories") & " WHERE LanguageID = @LanguageID"
            MyCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LanguageID", LanguageID))

            Dim MyDataAdapter As New SqlClient.SqlDataAdapter(MyCommand)
            Dim MyDataSet As New DataSet()
            MyDataAdapter.Fill(MyDataSet)
            MyConnection.Close()

            Return MyDataSet.Tables(0)
        End Function
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDatabase accessDatabase access


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out