Results 1 to 5 of 5

Thread: Use the connection string in App.Config

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Use the connection string in App.Config

    I have a connection string named in my app.config file but I don't know how to reference it with code. For instance what do I put in the connection string for this code block?
    VB Code:
    1. Dim cnn As New OleDbConnection
    2.         Dim cmd As New OleDbCommand
    3.         Dim dr As OleDbDataReader
    4.         cnn.ConnectionString = ""
    5.         cmd = cnn.CreateCommand

    My connection settings look like this
    VB Code:
    1. <connectionStrings>
    2.         <add
    3.           name="BarCodeReader.My.MySettings.db4ConnectionString"
    4.           connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\db4.mdb"
    5.           providerName="System.Data.OleDb" />
    6.     </connectionStrings>

  2. #2
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: Use the connection string in App.Config

    are you using vb2005? i'm assuming so since i see BarCodeReader.My.MySettings

    do the following...

    VB Code:
    1. Dim cnn As New OleDbConnection
    2. Dim cmd As New OleDbCommand
    3. Dim dr As OleDbDataReader
    4. Dim YourSettings As My.MySettings
    5.  
    6. cnn.ConnectionString = YourSettings.db4ConnectionString
    7. cmd = cnn.CreateCommand

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  3. #3
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: Use the connection string in App.Config

    sorry wait i'm not thinking for the way i'm doing something in my app

    all you need to do is...

    My.Settings.db4ConnectionString

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Use the connection string in App.Config

    Well that is pretty simple. Thanks.

  5. #5
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: Use the connection string in App.Config

    anytime

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width