 |
|
 |
This saved me so much time. Thank you so much for this post!
|
|
|
|
 |
|
|
 |
|
 |
Thanks so much for this. It was sooo easy to follow even a caveman could do it.
|
|
|
|
 |
|
 |
I can only express my gratitude with ridiculous amounts of money, which sadly i don't have right now.. but really thanks!!!
|
|
|
|
 |
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
Hi. If you like this project, you might also be insterested in a DataConnectionDialog component I am selling. Please see http://mjmeans.com/dcd.aspx[^] for more informaiton.
|
|
|
|
 |
|
 |
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?
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
Sure. Just use the email link at the bottom of this reply and CodeProject will send a private email to me.
|
|
|
|
 |
|
 |
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];
}
}
}
}
|
|
|
|
 |
|
 |
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()?
|
|
|
|
 |
|
 |
You should explicitly call Save() method
|
|
|
|
 |
|
 |
Do you have an example of how to call this from c#?
Joe
|
|
|
|
 |
|
 |
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().
|
|
|
|
 |
|
 |
Thanks for confirming that. I've attempted that method, but cannot see the method via intellitype.
|
|
|
|
 |
|
 |
Make sure your partial Settings code is in the correct namespace.
|
|
|
|
 |
|
 |
Thanks for the information. The correct namespace was:
namespace myapplicationname.properties{
}
|
|
|
|
 |
|
 |
Thanks so much. You explained the situation and gave a terrific solution.
|
|
|
|
 |