Results 1 to 5 of 5

Thread: [RESOLVED] What Variable Type to use in DB Connection String?

  1. #1

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Resolved [RESOLVED] What Variable Type to use in DB Connection String?

    Hello again. I am using a CommandDialog to obtain a path to a db, I store the .FileName in a string called dbpath which I declared in the general section with option explicit. I then have a button to connect to the db. I've tried to use the dbpath string and the dbpathtxt.Text in the connection string, and it tries to use the string, not whats stored in the string to connect. Here is my connection string.

    CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= dbpathtxt.text or dbpath( I tried both here) ;Persist Security Info=False;"

    So now when I try to connect, it tries to connect to dbpathtxt.Text instead of the value stored in dbpathtxt.Text. I have tried to use quotes single and double, but it will just error when I do that. So how do I store the path in a variable and get the db to read it like an address?

    This is the path that is in the textbox that I store in dbpath and that is dbpathtxt.Text.
    C:\Program Files\Microsoft Visual Studio\VB98\vb files\SQL Interpreter\briansdb.mdb

    This is what shows up when I try to connect.
    Could not connect to: C:\Program Files\Microsoft Visual Studio\VB98\vb files\SQL Interpreter\dbpathtxt.text.

    It does this no matter what directory I try to pull a db from. It is reading the path right, but it exchanges the last address with whatever I stored the path in.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: What Variable Type to use in DB Connection String?

    The connection string is just a string (with strict rules, but still just a string), so as you usually would, you need to append your variable to it, rather than putting the name of the variable inside the string, eg:
    Code:
    CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath & ";Persist Security Info=False;"

  3. #3

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Re: What Variable Type to use in DB Connection String?

    Hey thanks again. I finally made a connection! So when I connect with that string, I should be able to run sql commands on the db, like the ones I learned when I went throught that sql course?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: What Variable Type to use in DB Connection String?

    That's correct.

  5. #5

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Re: What Variable Type to use in DB Connection String?

    Whoo Hoo. Finally getting somewhere with this. Thanks a bunch.. If I could rep you again I would. I am pretty new to vb. i have been programming with basic since high school tho, quick basic, Just Basic, ect... I think me and vb will be good friends here soon. I like the way it tries to write the code for you. I have never used a compiler that does that before, it was annoying at first, but I see its usefullness now...
    Last edited by Brian M.; Jun 17th, 2007 at 02:52 PM.

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