[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
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.
Re: Question about connection strings
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
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?
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