Results 1 to 6 of 6

Thread: [RESOLVED] Question about connection strings

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Resolved [RESOLVED] Question about connection strings

    So I was reading this http://www.packtpub.com/article/conn...-visual-studio to learn about database crap as my apps are needing databases. the part that confuses me, if the path it uses
    Code:
    Dim compactStr As String = _
    "Data Source=I:\Folder\Folder2\Projects\App1 Platform\Compact\Compact\mydb_Apps.sdf"
    What or how does this work when you publish your app and give it out to people to use. Won't the database string be the above address for them too? in that case it is not going to work, right? Is there a way to configure these strings programmatically so they use address of the application?

    i am only getting started on the whole database thing and if i can get some pointers and advice in terms of how i should go about setting them up. would be great.

    thanks

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: Question about connection strings

    I have a codebank thread that allows you to change the connection string at runtime, just check in my signature under vb.net contributions. My whole vision for that codebank thread though, was to allow the user to change it with an Openfiledialog. It sounds like you just want the connection string to just change without any user interaction, which what comes to mind is the StartupPath property. Basically what you should do is, first in the form_load event, check if the file exist. Then if it doesn't exist, change the connectionstring to a file that's saved somewhere in your StartupPath.
    Last edited by dday9; Nov 6th, 2013 at 11:21 AM. Reason: speling an gramur
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Question about connection strings


  4. #4
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Question about connection strings

    If you are using the designer to drop your tables and use BindingSources, you might have noticed that on the Form Load's event handler you get by default this line:

    Code:
    Me.ItemsTableAdapter.Fill(Me.MyDataSet.Items)
    Just put, above that one, your corrected Connection string. How you build it is another story, with an INI, programatically, with user input, well, you decide...

    Code:
            Me.ItemsTableAdapter.Connection.ConnectionString = "This would be your connection string"
            Me.ItemsTableAdapter.Fill(Me.MyDataSet.Items)
    Note: ItemsTableAdapter is my particular Table, yours will be named differently, same goes for MyDataSet
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: Question about connection strings

    Thanks for the info guys. Instead of using My.Settings for the database connection, I want to use windows registry to get the database string using the install path. Is there a simple way to determine where my app gets installed? Yea Dday, I want to have each user use their own install directory's when accessing the database and have the database string the same as my apps install path. What methods could I use to determine a users install directory by reading the registry?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: Question about connection strings

    Never mind, this will work perfect for my needs and might help someone else.
    Code:
        Sub SetAppPath()
            Try
                My.Computer.Registry.CurrentUser.CreateSubKey("Software\Companyname\Productname\Version\")
                My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Companyname\Productname\Version\", "ApplicationPath", Application.StartupPath)
            Catch AppRegSetStartUp As Exception
    'add exception stuff if need. 
            End Try
        End Sub

Tags for this Thread

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