Tuesday, July 28, 2009

How do I reference a DSN in .NET?

I will be installing a VB.NET application on a customer's network. There will be two workstations that will use the application. The application uses an Access database. I will choose the project and database path at the time I install the application.


I would like to create an ODBC connection on each workstation that points to the database.





Given the described scenario, would it be best to reference a DSN in my code? If so, how do I do that?


Right now (for testing) my connection is simply:


--------------------------------------...


Module modGLOBAL


Public Const CONNECT_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TeamDevelopment\SIDS\StudentDa...


--------------------------------------...


This is just a test path on my system. How should I code this for the production application given the fact that I don't know where the database will reside until I install the application?

How do I reference a DSN in .NET?
Dear


There is a simple way that you use the windows registry, here you can store the database path in the Registry and read it whenever your application starts.you can use the following code to get registry file path in vb.net 2005 :





Dim path As String = _


My.Computer.Registry.GetValue("KEY_NAME"... "VALUE", "DEFAULT VALUE")





and use the fallowing code to set the path in the registry





My.Computer.Registry.SetValue("KEY_NAM... "VALUE", "DEFAULT VALUE")





It works,try it.

survey

No comments:

Post a Comment