?
Solved

vb.net build connection at first run

Posted on 2011-04-28
9
Medium Priority
?
208 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:miller75
9 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35486653
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
 

Author Comment

by:miller75
ID: 35486667
Sorry didn't say it was a windows app
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35486694
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Expert Comment

by:Tom Beck
ID: 35486771
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
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35486806
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
 

Author Comment

by:miller75
ID: 35486847
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
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 35487332
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35490461
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
 
LVL 2

Expert Comment

by:team2005
ID: 35505787
Hi!

Why not use xml, to store connection string.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question