Results 1 to 4 of 4

Thread: Connection string syntax with TableAdapter

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    52

    Connection string syntax with TableAdapter

    Hi guys, I am trying to use a variable for the path to my database but am not having much luck with the syntax.

    So I open my datasource and click on "Edit dataset with designer". I select the adapter I want to change and expand the "Connection" field.

    The current connection string is: Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\box.accdb

    I tried changing it to: "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & splash.path & "\box.accdb"

    but I get an error message appear which says "Property value is not valid: Format of the initialization string does not conform to specification starting at index 35."

    Does anyone know the syntax I'm supposed to use?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,467

    Re: Connection string syntax with TableAdapter

    There is no syntax that you're supposed to use. The connection string has to contain a connection string, not some VB code. If you want to change the connection string using VB code then you do that in the VB code. Done properly, that will look something like this:
    Code:
    Dim builder As New OleDbConnectionStringBuilder(myTableAdapter.Connection.ConnectionString)
    
    builder.DataSource = IO.Path.Combine(splash.path, IO.Path.GetFileName(builder.DataSource))
    myTableAdapter.Connection.ConnectionString = builder.ConnectionString

  3. #3

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    52

    Re: Connection string syntax with TableAdapter

    Thanks mate, but where would I place that code?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,467

    Re: Connection string syntax with TableAdapter

    Quote Originally Posted by amaru96 View Post
    Thanks mate, but where would I place that code?
    What is the point of the code? To change the connection string of a table adapter. Where do you want to change the connection string of a table adapter? That's where you put the code.

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