 |
|
|
 |
|
 |
The work involved in this is great. I have used this as a basis and reworked the ctrlConnection control and the frmConnection form to now use in either a SQL Server or Windows authentication scenerios. Everything works fine until I compile as a dll and use it in another project. I then tried the original in the same format to ensure it wasn't something I did. The program always gives an error when attempting reset the default so it can be used during this current runtime even though it did get it saved. If I add the control and form directly in the new project, then it works. Too bad as this would really help for code reuse situations.
Note: I did have to change one line in the ctrlConnection control of the SaveChange subroutine:
ConnectionFullName = String.Format("{0}.My.MySettings.{1}", System.Reflection.Assembly.GetExecutingAssembly.GetName.Name, connectionName)
was changed to:
ConnectionFullName = String.Format("{0}.My.MySettings.{1}", _
System.Reflection.Assembly.GetEntryAssembly.GetName.Name.Replace(" ", "_"), connectionName)
Great job!!
|
|
|
|
 |
|
 |
Thanks so much for contributing your software!
I'm not getting any errors when I run your code (SettingsDemo2), but the changes I make to the connection string aren't being saved. Every time I re-run the code, I get the Northwind DB settings.
I spent several hours with the debugger (I'm using Visual Studio 2008); at some point it loses the connection string value. I thought it might be related to the ConnectionStringChanged() event... but, I can't find that event anywhere! Can you tell me which file that event is supposed to be in?
Perhaps I'm looking in the wrong direction If there's something else I need to do to make the SAVE function work, please let me know
Thanks again!
Tracy (Her Highness, around the house anyway!)
|
|
|
|
 |
|
 |
Hello,
Thanks for this brilliant piece of work, I am getting a error when I do the following.
When I enter settings in the SQL Connection Builder and click test, I get the "verfied as working message" and then click ok, the demo connection textbox contains the connection data I just entered. but when I click "OK" in the settings page, I get this message:
Failed saving connection 'DemoConnection':
There is no connection with this name defined in the config file.
** Further to this **
I have got the connection to update, but the app is not creating demo.txt in c:\ (Is this normal), when I close the app and reopen the new setting are stored.
Any Ideas?
Many Thanks in advance for any help provided.
Andrew Harris
modified on Saturday, December 08, 2007 4:40:02 PM
|
|
|
|
 |
|
 |
AndrewHuk wrote: Failed saving connection 'DemoConnection':
There is no connection with this name defined in the config file.
Yes, I got it too.
|
|
|
|
 |
|
 |
The demo project u hav provided ask for the user name and password. I have authenticated SqlServer 2005 using Windows Authentication. So when user name n password is not provided,it does not connect to the database when i 'Test' it.
What should i do then????
sudeep
|
|
|
|
 |
|
 |
Thanks for this work, it is much appreciated and has stopped premature baldness through head scratching!
|
|
|
|
 |
|
 |
Hi,
I have copied the ctrlConnection and frmConnection to my project and set the references. I then dragged the control from the toolbox and set the properties. All this seem to work well.
After reading the post above, "update app.config during runtime?", I am confused as to when the users opens the app on the second day, will they need to go through this process again. I see the config.save is saving it to the config file, so they should not have to do this process each day? Correct? But from reading the above post, it sounds like they may.
I have tested it here in my shop. I have deployed it to other PC's, ran it, and changed the connection string. When I close it and open it again, the connection string is still showing the second one, which is what I changed it to. So it appears to me this process should only have to run once after an installation. Is this correct?
Also, does the logon have to have admin rights for the save to work?
Thanks a lot,
Steve
VS2005
VB .NET
SQL2005
|
|
|
|
 |
|
 |
Yes, the value is permanently saved to disk. That is the point.
User rights will depend on where you deploy your file. The config file goes into the same directory as your EXE file. If you deploy into a directory where the user is able to edit you have no problem.
|
|
|
|
 |
|
 |
Hello.
I'm new at VB.Net and I don't understand much this app.config file
and I did't succeed to change ConnectionString using your sample project.
I'm working on a project that works on SQL200 and VB.Net but this project work fine
only on my computer. (because of the connection string ):-/
I want to ask you a favour....
Can I send you my project with all needed forms so you can
modify the code that this change of ConnectionString will work?
I have a startup form where you type in your server name and default database,
and when you press OK I want to change ConnectionString...
(I didn't succeed this myself)
Please, reply to my mail: pinky85@post.t-com.hr
(I don't use markobrljak@gmail.com anymore)
I wolud be very gratefull to you.
|
|
|
|
 |
|
|
 |
|
 |
Sorry, I don't have the time to engage in extensive hands-on support ....
If you download the code I am sure you will be able to work it out yourself.
|
|
|
|
 |
|
 |
Hi
Great example!
I have one question(I'm quite new to vb.net).
My test application loads with default connectionString and I often need to change database.
Can I change, with your code, connectionString without restarting application?
Let's say from menu item open new database(ms access)?
Best regards,
t.
|
|
|
|
 |
|
 |
Sure, that is the whole point!
But you need to be aware of open connections and already loaded data, to make sure they are reloaded after your change.
Please observe also that my example code will not cover connections to Access databases. You need to extend that yourself.
|
|
|
|
 |
|
 |
Hi Jakob,
Thanx for reply!
I have managed to extend it to msaccess database.
Best regards,
t.
|
|
|
|
 |
|
|
 |
|
 |
i just wanted to verify exactly how this works:
I have a setting in 'My Program' as ConnectionString; Type: (Connection String); Scope: Application. Using what you have described above, I should be able to change the value for that setting during run time, right? therefore all my tableadapters will then use the new connection string...
will this update/refresh as soon as i change the value in the settings? or do i have to do anything more? isnt the type(connection string) readonly? will this actually edit the app.config file? do i ahve to restart my application after editing the connection string?
i am a newbie to this so please excuse my many trivial questions...
thanks alot.
|
|
|
|
 |
|
 |
Type=ConnectionString and Scope=Application is correct. That is what I use too. You can store the connection string as a normal String which will make it easy to change through the My.Settings object. But since the designer built adapters always use the ConnectionString type it is interesting to find a mechanism to edit that too.
Yes, ConnectionString type is ReadOnly in the My.Settings object. That is why I did this workaround to bypass the My.Settings object.
No, you don't need to restart the application. As you can see in my code comments I first write the value to the config file, and then also change the runtime value.
Yes, it is correct that the changed value will be written to the config file. But strictly speaking there is no app.config at runtime. The config file is renamed into YourApplicationName.exe.config.
Good luck.
-- modified at 4:24 Thursday 1st March, 2007
|
|
|
|
 |
|
 |
thanks for the reply.
so will i have to change the connectionstring everytime i run the application? or if i change it once(during runtime), then it would use the new connectionstring and not the old one which i saved in the myprogram setteings during developement.
cause basically i have a different connectionstring during developement but i want to have the ability to chnage that during runtime and then have that changes saved so i dont have to edit the connectionstring everytime i run the application.
thanks again
|
|
|
|
 |
|
 |
If you set it in runtime it will stay in runtime. Why don't you try it, and check it yourself?
You should of course still change the default setting runtime value before you distribute your application to customers.
|
|
|
|
 |
|
 |
Yes it stays during runtime, but if i exit and re-run the application it stil have the old connectionstring.
I can not chnage the default value because this application will be distributed to various people so i cant chnage the connectionsring for each one.. they will have to do that themselves.
any suggestions on how i can save the changed connectionstring so that i dont have re-enter everytime and run the application.
thanks
-- modified at 16:27 Wednesday 28th February, 2007
ok, i figured it out but i dont know if its the right/best way to go about this... i created another setting (constr) which is type String and scope User.. this saves a copy of the Application Scope connectionstring... and then during startup i check if i can connect with constr, if i can then i copy that string to the application scope string using your code and changing "Me.ConnectionString" to "My.Settings.constr"
'Set value and save it to the config file
Setting.ConnectionString = My.Settings.constr
Config.Save(ConfigurationSaveMode.Full)
'The above will still not change the runtime value,
'so this needs to be changed explicitly.
My.MySettings.Default.Item(connectionName) = My.Settings.constr
if i cant connect with constr then i popup the form for them to add the new connectionstrin.. copy that to my.settings.constr
this way the user will enter it only once and the applicationstring would be changed during runtime to constr...
hope it makes sense
Thanks!!
|
|
|
|
 |
|
 |
In design mode you will only have temporary files, so to really note that config file value is changed you need to deploy the application. Also make sure you call the SaveChange method of the control!
Why do you need to change database connection on all clients? In my applications the clients usually connect to the same database and I provide them with the correct connection string at startup. For security reasons I actually don't want my users to know the complete connection string. If you need another database connection during testing, that's fine but it should not affect all users after a release!
If you want to keep another connection string settings, it is OK with me, but it looks like overkill. What I typically do is start the application by reading the connectionstring value once (before the first database call!) and try to open a dummy connection. If that does not work I display the connection wizard and ask them to define another connection before they are allowed to proceed.
|
|
|
|
 |
|
|
 |