views:

162

answers:

2

Hi.

Does anyone know if it is possible to create a single connection string that will be accessible to all the projects in a solution (we have about 6). I can create a text file with this information, but we need design time support as well, and it is not practical to have a connection string in every App.Config and Web.config file in the solution. We basically want a Single connection string that is easy to change should the location of the db change, that will also be used by the IDE for design time support

Regards, Renier

+1  A: 

Not sure, can't you just put a new config file to the solution items and include and load it in all projects?

Edit: I am specifically talking about a general (XML) config file, not an "App.config". Is has exactly the same format, it just goes by a different name. Add this file to your solution items and access it using OpenMappedExeConfiguration. You can find an additional example here.

mafutrct
This does not seem possible... but i might also miss something. As mentioned in comment above, I am quite new to .net
Renier
OK This is getting very useful now. I have also managed to write a very similar function. The same principle will apply.In the Settings.settings file of our one DLL, I declared a connection string. This can be accessed in the following way for FormName.Designer.csthis._connection.ConnectionString = global::MyDLL.Properties.Settings.Default.MyConnectionString;The last question i have, the *.designer.cs files are system generated. If i were the connection string in the designer.cs file, and I then make changes to the visual designer, will it delete this manual addition that I have added?
Renier
I'm sorry, I don't know that. Maybe just try it out? :)
mafutrct
OK It seems to work without any problems, well at least for now. :) THanks a lot!
Renier
You're welcome. Btw, if you don mind, upvoting an answer marks it as helpful. ;)
mafutrct
I tried but dont have an account, must still register. Will do as soon as I have registered.
Renier
OK My reputation is not high enough to Vote Up yet... sorry. If someone else could vote up on my behalf it would be appreciated.
Renier
Don't worry about it too much xD
mafutrct
+1  A: 

put the connection string in the config of your "main" project. Create a Data Access project with a connectionstring property. Set this property when you initialise your project and use the Data Access project for all database related actions in all 6 projects

Ivo
That will only work if there is a main project, not if e.g. several projects each produce an .exe.
nos
You can also but the connectionstring in the config file of the Data Access project. This way you only have it at one place
Ivo
Ivo... This is basically what we tried... but i can only access it at runtime. We need design time support as well (Especially for DevXpress reports). We are running in a postgreSQL database and use Devart's UniDirect components.
Renier