vb.net build connection at first run

I have developed a small app with the connections string to a SQL database in the .config file, this is fine on my development machine but when I try to deploy it on another machine it obviously needs changing, as the config file is read only at runtime what is the best way of handling the connection change.
miller75Asked:
Who is Participating?
 
Tom BeckConnect With a Mentor Commented:
Another sub app could be added to the application that could edit the app.config file. Maybe add a "Settings" or "Advanced" button somewhere in your app.
0
 
Tom BeckCommented:
Just change the web.config file on the server where the web application is deployed. You can even do this while the sit is live. Or, upload a corrected one to replace the original.
0
 
miller75Author Commented:
Sorry didn't say it was a windows app
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Tom BeckCommented:
If the string is embedded in the code then you will have to correct and recompile. The better way to handle it would be to put your connection strings in the app.config file. Works the same as a web.config file.
0
 
Tom BeckCommented:
Here's a sample local sql connection entry in the app.config file:


    <connectionStrings>
        <add name="myWinApp.My.MySettings.myDbConnectionString"
            connectionString="Data Source=machineName;Initial Catalog=myTable;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>

Place this in the configuration section of the app.config file.
0
 
Tom BeckCommented:
Very easy to access in code using MySettings:

Dim SqlConnectionStr As String = My.Settings.myDbConnectionString

You can store any kind of data that is likely to change over time in the app.config file like passwords or email addresses, etc.
0
 
miller75Author Commented:
This is what I am currently using, the problem I have is if I send the app to the end user I want them to be able to build the connection string rather than having to edit the app.config file manualy
0
 
CodeCruiserCommented:
You can change the scope of the setting to User rather than application and then its not readonly. Then the user can change it on the Settings form within your app and you can modify it from within your code.

My.Settings.ConStr = "New con str"
My.Settings.Save()
0
 
team2005Commented:
Hi!

Why not use xml, to store connection string.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.