0

I'm developing a Windows Form application with Visual Studio 2013 that needs access to multiple Oracle databases.

The main application is an MDI window and from a menu you can open many different child forms. Each child form has access to a different Oracle database and shows different DataGridView and other data controls.

I'm using Oracle Developer Tools and the child forms contains Oracle controls taken from the VS Toolbox, using drag and drop and wizard, so DataBinding is automatically configured.

The solution consists of 3 projects: Main Application EXE (contains forms, DataSet.xsd and .config files), Data Access Classes DLL, Reports DLL (contains RDLC reports as embedded files).

For each database I need to refer to the same ConnectionString, both for design time (used by wizards) and runtime. At design time, the form controls automatically use a reference to the DataSet.xsd file and so the ConnectionString automatically created the first time with the wizard. Then I also need to access to the same database during runtime and so when I deploy the application I need to keep all the correct references, both for debug and release.

Now I have all the ConnectionStrings and DataSets XSD files stored on the Main App EXE project and my actual config files are:

DataSet.xsd and .config files

When I add a new report on the Reports DLL project using the Report Wizard Tool, I'm asked to create a new DataSet and so a new ConnectionString because Visual Studio doesn't show me the existing connections stored inside the Main App EXE project.

To sum up I need to be able to:

  • Share ConnectionStrings between Main App EXE project and Reports DLL project;
  • Share DataSets XSD files between Main App EXE project and Reports DLL project;
  • Have distinct ConnectionStrings for Debug/Release and share them all between projects;
  • Automatically update DataSets XSD files whenever I make changes to the underlying databases;
  • Change database context (test environment for debug and production environment for release) without breaking DataSet.xsd or, if this is not possible, by having two distinct DataSet XSD files, one for test and another one for production, that are automatically selected based on the debug/release mode.

Now I need to manually change code in XSD file to replace the ConnectionString (test/production). But since the DataSet refers to the same database structure I need a mechanism to make this easier.

Cheshire Cat
  • 1,941
  • 6
  • 36
  • 69
  • Connection string settings are available since .NET 1.0. Just go into your project's properties and add a new setting with a Connection String type. You'll find multiple tutorials on how to use the stored connection string in datasets, report builders etc, without having to explicitly change each component's connection – Panagiotis Kanavos Oct 07 '15 at 13:08
  • Yes, I know that ConnectionStrings are stored inside the Settings.settings file insiede Properties folder. There I can see my 2 ConnectionStrings for my actual 2 DataSet.xsd for test environment. How can I make those settings solution wide, without copy/paste (and so then change if needed...) in each project? And how can I satisfy my needs? Can you give me some hint on those tutorial you're referring to? – Cheshire Cat Oct 07 '15 at 13:16
  • If you have only one executable, you don't need any solution-wide settings. Just put the relevant settings in your application's `app.config` - ie copy them from the dll configs to the exe config. – Panagiotis Kanavos Oct 07 '15 at 13:18
  • All the settings are already stored inside the app.config file on the Main App Project. But for this reason, when I create a new RDLC Report with the Wizard, VS probably looks for connection only inside the Reports project and then asks me to create a new connection because there're none. – Cheshire Cat Oct 07 '15 at 13:35
  • You could extract the connectionStrings section to another file [as shown in this SO question](http://stackoverflow.com/questions/6940004/asp-net-web-config-configsource-vs-file-attributes) that's referenced by all projects. – Panagiotis Kanavos Oct 07 '15 at 13:46
  • This doesn't work with Report Wizard. The settings used by the wizard (so at design time) are stored inside Settings.settings file. I need to share them too. – Cheshire Cat Oct 07 '15 at 13:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91616/discussion-between-cheshire-cat-and-panagiotis-kanavos). – Cheshire Cat Oct 07 '15 at 14:16
  • Another approach: you can manage the connection and associated string yourself and then set it on the TableAdapters' connection property. – peterG Oct 10 '15 at 23:18
  • I'd like to do it, but how about design time with wizards? When I drag & drop components in forms and reports too, the connection and the Dataset are linked automatically. Since the application development should also be entrusted to another non-expert person, I need wizards to work. – Cheshire Cat Oct 11 '15 at 15:34
  • @Cheshire Cat I'm not sure what you mean about the non-expert person really. Anyway, an approach I've used a lot is to build a DAL object with all the datasets and tableadapters in it, and then as part of the initialisation of the app, get the connection string (from wherever - menu, options supplied by the user, etc) and then apply the string to a connection and set the connection property of all the tableadapters to this connection. I generally also open and close the conn. programmatically btw. This way it's not doing multiple opens and closes when a function uses multiple TA's – peterG Oct 13 '15 at 15:52

0 Answers0