VB2005 Typed DataSet connection string

I have Typed DataSet (ABC.XSD) and the Setting information (strCON) appears in the Property page as

"User Id=AAAA;Password=BBBB;Server=CCCCC.WORLD"

This places the information in the exe.config file where it is visible. What I'd like to do is remove the strCON in the Settings and place the connection string in a class (i'm guessing a partial class of the ABC.XSD) What do I place in the partial class



Answer this question

VB2005 Typed DataSet connection string

  • Allan Huang

    rSchild,

    There are many ways to put your ConnectionString of database in your project. Write the connection string in config file is one commonly used method. However, you can also write your strCON in the program, such as a class file like your project: a partial class of the ABC.XSD. The following code sample will help you to put the strCONin the Settings and place connection string in a class:

    Private Sub OpenSqlConnection()

    Dim connectionString As String = GetConnectionString()

    Using connection As New SqlConnection()

    connection.ConnectionString = connectionString

    connection.Open()

    Console.WriteLine("State: {0}", connection.State)

    Console.WriteLine("ConnectionString: {0}", _

    connection.ConnectionString)

    End Using

    End Sub

    Private Function GetConnectionString() As String

    ' To avoid storing the connection string in your code,

    ' you can retrieve it from a configuration file.

    Return "User Id=AAAA;Password=BBBB;Server=CCCCC.WORLD"

    End Function

    I hope it is helpful to you!



  • VB2005 Typed DataSet connection string