Question Change to different SQL Server database

markyork

New member
Joined
Oct 30, 2014
Messages
1
Programming Experience
5-10
I have a VB.NET (4.5) project in VS2013. In it I have several DataGridViews populated by a SQL Server 2012 database. The DGV and connection has all been set up with the wizards, so I have BindingSources, DataSets and TableAdapters for the DGVs - no custom coding to populate the DGVs.

I need to change to a new Database (for now the DBs are identical) and can't figure out how.

I tried changing to the DB name in the project properties Settings tab. That just caused the DGVs to not be populated at run time.

I went so far as to do a text search for the old database name in the entire project and change that to the new database name, but that (not surprisingly) just broke everything (errors and the DGVs didn't get populated).

What is the correct way to change the source database when the DGVs have already been connected to a database? I'm guessing one way to do it is to remove the existing DataSets, BindingSources, TableAdapters, etc and rebuild them, but I'd like to find out if there's something less radical and time-consuming than that first.
 
When you use the wizard to create a database connection and accompanying objects, it will add a connection string to the Settings page of the project properties and that connection string is also stored in the config file. If you want to change database during development, you go into the Settings and edit that connection string. Doing so should open a dialogue specific to the purpose and allow you to choose a server and database courtesy of the SQL Browser service. It should also allow you to test the connection in that dialogue.

If you've done that and you see no data then either there is no data in the new database or an exception is being thrown when you try to retrieve the data, so make sure you have your data access code in an exception handler, especially if it's in the Load event handler of a form, where the debugger will not pick it up otherwise.

After your app has been deployed, the connection string in the config file can be edited by hand to change the database it connects to.
 
Back
Top