 |
|
 |
I created my tableadapters in a class library project called ConfigurationControl I think this is exactly what I need but I was wondering how do I use it from another project.
I added the Module called Settings.UserOverride.vb to the ConfigurationControl project but now I need to access it from the Main Data acquisition project. Can I access the ConfigurationControl settings class from the other projects? or do I create another sub routine, say in Module1 of the ConfigurationControl project that then calls the SetUserOverride routine.
<pre> Module Module1 Public Sub SetNewConnectionString(ByVal settingName as string, ByVal value as String) My.Settings.SetUserOverride(settingName, value) End Sub End Module1
With this, I should be able to call the SetNewConnectionString from the Data Acq. project on startup and change the connection string before using any of the table adapters, right?
Thanks for the help. I appreciate it so much
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hmmm.
If you make the MySettings class in your class library Public and make sure the class library is in its own namespace, then you should be able to access it from your other projects, such as OtherClassNamespace.My.Settings.ConnectionString = "server=local;etc". Putting it in another namespace will ensure that the hard coded Settings class name will not conflict with another projects namespace.
If you can't put the library in another namespace for design reasons, then you can add a different public class you can call to access the that libraries settings.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi thanks for the response.
This is what I did
After adding the code in this article to the class library (ConfigurationControl), I added a module called Module1 where I created 2 public methods to access the class libraries settings
Module1
Public Sub SetNewConnectionString(ByVal name as string, Byval value as string) My.Settings.SetUserOverride(name,value) End Sub
Public Function GetNewConnectionString() as string Return My.Settings.DatabaseConnection.ToString) End Function
Now from my other project I call ConfigurationControl.SetNewConnectionString("DatabaseConnection",connString) when change the connection string upon startup.
It seems to be working correctly but I wanted to make sure this was an appropriate solution.
Just out of curiosity, how would i make the settings class of the class library Public as you suggested? Thanks again for the help
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You just click the icon in solution explorer to show all files, then open up the settings.designer.vb file. Change the class to public in settings.designer and also in the code from my article.
Another way you could do this is to pass the connecction string in the NEW. You would do this by changing your table adapters class to Friend (or internal) which would block its access. But then add a new Public class that inherits the table adapter and set its constructor to New(connstr AS String).
Also, if you're looking for a connection string editor, check out my link at the bottom of the article.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
mjmeans wrote: Another way you could do this is to pass the connecction string in the NEW. You would do this by changing your table adapters class to Friend (or internal) which would block its access. But then add a new Public class that inherits the table adapter and set its constructor to New(connstr AS String).
I originally looked at this option but I didnt want to have to do it for every table adapter everytime.
mjmeans wrote: You just click the icon in solution explorer to show all files, then open up the settings.designer.vb file. Change the class to public in settings.designer and also in the code from my article.
I did this and I am still not able to see the Settings class. the furthest I can get is otherNameSpace.My.MySettings and then intellisense gives me nothing
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi. Thanks by your code. But, I have a big problem: my solution have 8 projects and I have ConnectionsStrings in all of then. When we build a publisher/package to deliver our app to customers we need change the app.config to reflect the new enviroment (the server name and passwords). But if we change the value of app.config only the main project is afected. The others projects don't update to the new value.
How to fix this issue?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
That could be complex or simple, depending on how your distribution is created. There's a number of ways to do this, involving command line switches or modifying the sub-apps to read the main apps app.config file. But anything along this line would have problems if the other executables are already running, since the config file may be locked. Note that reading or writing another apps config file could pose problems in Vista if all the config files are not in the same folder. A better idea is to use the registry to flag when each sub-application needs to retrieve an upadated connection string. You would set up a registry key for each sub-application like HKLM/Manufacturer/Product/SubApp1UpdateConnectionString=NEWSTRING. Each sub-application would check in StartUp() for the existance of this key when they start, and if it is found update their own connection string, call My.Settings.Save() and then remove the registry setting so that that it doesn't get re-applied.
If your other apps are DLL's, then there is an additional problem.... since they may have already created their DataAdapters and would then have an OLD copy of the connection string. In this case, you will probably have to save the connection string and then restart the applcaiton unless you add code to each of your DLL's to recreate the DataAdapters.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I was desperate 'cause I didn't know how to deploy a project containing a little sql server ce. I spent 3 days trying to avoid errors given by the application when I tried to show in a form data present within the DB.
THANKS A LOT!
Frankie
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
Your code is an excellent solution to this problem - and I would like to use it in my A-level coursework for Computing. Would it be possible to e-mail you with regards this?
Thanks very much Alex
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sure. Just use the email link at the bottom of this reply and CodeProject will send a private email to me.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I converted your great article to C# and it worked great. Here's my version.:
namespace xxx { public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static string[] userOverrides = { "constring1", "constring2" }; private static string userOverrideSuffix = "UserOverride"; public void SetUserOverride(string property, string value) { this[property] = value; }
protected override void OnSettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e) { string userProperty = null; foreach (string appProperty in userOverrides) { userProperty = appProperty + userOverrideSuffix; if (((string)this[userProperty]).Length > 0) { this[appProperty] = this[userProperty]; } } }
protected override void OnSettingsSaving(object sender, System.ComponentModel.CancelEventArgs e) { string userProperty = null; foreach (string appProperty in userOverrides) { userProperty = appProperty + userOverrideSuffix; this[userProperty] = this[appProperty]; } } } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hey. Great! I didn't realize that the normally VB only aplication framework would actually work in C#. Is it actually saving the changed settings on exit, or do you have to set some other properties and handlers in main()?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Just call SetUserOverride(...). For example:
xxx.Properties.Settings.Default.SetUserOverride("constring1",_NewConnectionString); where: 1. xxx is settings class namespace, 2. "constring1" is your old connection string name, 3. _NewConnectionString is your new connection string.
If you want to persist changes, call Save().
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
You're welcome. I accept donations. If you have a small country you no longer want, I'll be glad to accept it. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank You I think My.Settings.Item("ConnectionStringName") = NewConnectionString will make me able to change the connection string with out any classes Am I right?
George Batres
modified on Thursday, December 4, 2008 9:47 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
If you are using a connectionstring which is automatically created by the visual studio, that connection string is an application scoped connection string an is read-only. The command you offer will change the string only in-memory an will not save the connection string. So next time you run the application, the change will be lost unless you have found some other way to recall the change string. Also, since tableadapters reference only the name of the connection string explicitly, then if you have table adapters added to the project when in forms design mode and you load your updated connection strings outside of the 'settings' or 'my.application' classes there is a possibility that a table adapter gets initialized prior to your loadding the new connection string and that will cause the table adapter to use the wrong string.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
i do what u ask
my connection is natconnectionstring scop applecation ok i have one connection string natconnectionstring
i put in the overide like u tell in the place of connection1 i remove connection2
i use the class as u tell me but nothing
help me please explan exactly what we do or please
attach simple project that do this class
pleassssssssssss
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
It is probably step 3 that you have not understood. You need to check to see the name of the connection string you used when you created your datasets. This is the name that your strongly types dataset and table adapter expect to use. And it is that name that must be used instead of connectionString1 or connectionString2 in the examples above.
This example ONLY works with strongly typed database access. It could be adapted to use other datasets, but that is project left to the reader to accomplish on their own.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |