Note that there are some explanatory texts on larger screens.

plurals
  1. POMy.Settings.MyConnectionString works but app.config dont?
    text
    copied!<p>I'm not a WinForms developer, but have been doing ASP.NET for quite some time. I have to write something in VB.NET that just pushes some simple data to a database. So I created the VB.NET WinForms app (Visual Studio 2005).</p> <p>When I run the app it works fine for using:</p> <pre><code> Dim conMyData As SqlConnection Dim cmdInsert As SqlCommand Dim isSaved As Boolean isSaved = True conMyData = Nothing Try conMyData = New SqlConnection(My.Settings.MyConnectionString) cmdInsert = New SqlCommand("insComputer2", conMyData) </code></pre> <p>It also works fine if I use:</p> <pre><code> Dim conMyData As SqlConnection Dim cmdInsert As SqlCommand Dim isSaved As Boolean isSaved = True conMyData = Nothing Dim str As String = ConfigurationManager.ConnectionStrings("connect").ConnectionString Try conMyData = New SqlConnection(str) cmdInsert = New SqlCommand("insComputer2", conMyData) </code></pre> <p>That is, if I define the connection string inside of the properties of the project. If I build my project, snatch the .exe from the bin\debug folder and run it on my desktop, it works ONLY if I have the version that says My.Settings.MyConnectionString</p> <p>Otherwise, if I use the other version where I am pulling the connection string from my app.config file it only works if I run the project through visual studio, it will not run by just opening up the .exe on my desktop. It syas something like ConnectionString not set, or sometimes it states object not set to an instance of something...</p> <p>My question is: why does it work from within the project? </p> <p>Is it because when I build the project it cannot reference that app.config file since I've moved it to my desktop?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload