The DataSet's TableAdapter generates strongly types classes in VS.NET, with properties to connection strings that are read-only at runtime, unless, of course, you choose the "User" scope. Follow these steps for changing the connection string upon application startup:
- Open up the Settings.settings file, whatever it might be named in your project. If it's not there, create one by a) adding a new Settings file to your project, b) adding a new (Connection string) setting, c) save it, d) then ensure that each DataSet's TableAdapter's Connection property references this Settings file's (Connection string) setting.
- Press the F7 key to view its code.
- Add the following code to the Settings() constructor:
this.SettingsLoaded += new System.Configuration.SettingsLoadedEventHandler(Settings_SettingsLoaded); - Add the following method to the Settings class:
private void Settings_SettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e) { try { Settings.Default["PrizeWinsConnectionString"] = "PUT YOUR CONNECTION STRING HERE!"; } catch (System.Exception err) { throw; } } - Save and recompile your project/solution.
3 comments:
I wonder whether is not same as before where you read the config file values. Is there any change.
http://aspnetcsharp4.blogspot.co
Thank You. I've been banging my head on a wall all weekend looking for a solution. You are the man. It worked like a champ.
I like your blog analyze.This is one of the good application.Nice to read about your post.Supper.
Post a Comment