Monday, 15 February 2010

c# - App.Config Connection String -



c# - App.Config Connection String -

in windows form have connection string in app.config

<configuration> <configsections> </configsections> <connectionstrings> <add name="database" connectionstring="provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\database.accdb" providername="system.data.oledb" /> </connectionstrings> <startup> <supportedruntime version="v4.0" sku=".netframework,version=v4.5" /> </startup> </configuration>

and in classes using next code connect database.

string connstring = configurationmanager.connectionstrings["database"].connectionstring;

but not connected database.

can point out mistake.

but when utilize code without utilize of app.config works fine.

string connstring = "provider=microsoft.ace.oledb.12.0; info source = c:\\users\\amrit\\desktop\\database.accdb; persist security info = false;";

how can create app.config connection string work..

you may

<configuration> <appsettings> <add key="applicationtitle" value="sample console application" /> <add key="connectionstring" value="server=localhost;database=northwind;integrated security=false;user id=sa;password=;" /> </appsettings>

then utilize configurationsettings.appsettings["connectionstring"];

c# winforms database-connection connection-string

No comments:

Post a Comment