Allow users to select between a Prod and Test database

Seeker#1

New member
Joined
May 23, 2022
Messages
4
Programming Experience
3-5
I have been tasked with converting a Access Application to WinForms VB.Net. The Access application has the ability to swap between a Test and Prod database for training. I was wondering if it is possible to do the same with a WinForms app. I am using Datasets to connect to the SQL database. I have heard my.setting is not accessible at runtime. I read something about having two different connection strings. Neither of these were resolved in the post so not sure how either would work. Any help would be much appreciated
 
Does that mean a typed DataSet?
Thank you for looking at this. Yes, It is strongly typed. I use Dataset designer it creates a .xsd file. Is that what you are talking about? I was wondering if anyone has a application that allows the user to switch between database connections. The more I think about the the more issues I see, but then I have been know to over think things. I was thinking about a parameter but the user would have to have access to the program directory. Thought about a flag in a table on the database but then that flag would have to be maintained on both databases and could be "T" in one and "P" in the other, that wouldn't be good. Maybe its not possible without two separate versions.


Dataset.png
 
Open the Settings page of the project properties. There, you should see the connection string that was generated when you created your DataSet. That connection string is also stored in the config file and can be accessed via My.Settings in code. You can add another connection string on that page if you want and it will be stored and accessed the same way. You can then set the Connection.ConnectionString property of each table adapter based on the user's choice.
 
That would be great. The deployed application is a exe. I don't currently deploy the config file with the application. Doesn't meant I can't if I need too. I thought about having two connection strings but wasn't sure how to implement the switch. I created two connection strings called LaserMaintLogConnectionString and LaserMaintLogConnectionStringDev. They point to two different servers.
Data Source=WJBProduction;Initial Catalog=GMS_LML_Online_Data;Integrated Security=True
Data Source=WJBDevelopment;Initial Catalog=GMS_LML_Online_Data;Integrated Security=True
I have a Log In form, I am thinking at that point having the user select which connection they want to use. How would I code that. Thanks again.
 
Last edited:
You would have one variable for the connection string to use. When the user makes their selection, you assign one of the two possible connection strings to that variable. Every time you create a table adapter, you set its Connection.ConnectionString property using that variable.
 
> I thought about having two connection strings

Would the user log in to this application? How would the user switch between the two databases - via a selection at startup, or can they switch on the fly?
Does your application have other general settings?
 
For this application I use their Network Id to find them on a Security Table. There are some saved settings that determine what options are available on the menus. I thought about having a field on the security table that would indicate if they are training. Another option is to have a different version compiled with the Dev database connection string somewhere on the Network and have them use it for training. I was hoping someone would point me in the right direction. Ignore the attachment that's for a different app where the users Log in.

Thanks
 

Attachments

  • Untitled.png
    Untitled.png
    48 KB · Views: 10
Last edited:
Back
Top