Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Connection String Woes
Message
 
To
12/08/2010 00:25:11
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01476326
Message ID:
01476328
Views:
37
>>I'v got this in my app.config:
>>
>>
>>    add name="ConnString"
>>         connectionString="Data Source=MAROIS_MAIN_PC\SQLEXPRESS;Initial Catalog=AppSecurity;Trusted_Connection=Yes " 
>>         providerName="System.Data.SqlClient"/
>>
>>
>>I'm trying to read it like this:
>>
>>
>>if (_ConnString == string.Empty)
>>{
>>    _ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
>>}
>>
>>I get "Object reference not set to an instance of an object"
>>
>>After an hour of trying all manner of things, and no results from Google, I changed it to this:
>>
>> _ConnString = ConfigurationManager.ConnectionStrings[0].ConnectionString;
>>
>>and it return a string, but this is what gets returned
>>
>>
>>data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
>>
>>
>>What the hell is going on??? What's the right way to do this???
>
>You are using an app.config, but I'm assuming your app isn't seeing it and is reading the web.config. That value that you see is the default connection string that is included in a new web.config file.

It's a WinForms app, not a web app. There's no Web.Config - that I can see

Thing is - I'm using this same app.config in other apps, and I read it the same way. The only difference is the DBML I added to my project, which has a conn string embedded in it. I have the Application Settings property set to False, and there's nothing in Settings.Settings.

The only conn string I can see in my app is in the DBML (not used as above) and app.config.

Another thing. I started this at the office where it worked fine, the brought it home where I'm now seeing this. I unzipped it & ran it, and now it can't see the app.config.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform