Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Connection String Woes
Message
De
12/08/2010 00:25:11
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01476326
Message ID:
01476327
Vues:
49
>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.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform