c# - Connect to a MSSQL DB using Web.config -
i have created asp.net c# mvc
project. trying connect mssql
db. in web.config
file added following;
<connectionstrings> <add name="sdbconnection" providername="system.data.sqlclient" connectionstring="data source=(localdb)\v11.0;attachdbfilename="c:\users\o\documents\visual studio 2012\projects\ppl\ppl\app_data\ppldb.mdf";integrated security=true" /> </connectionstrings>
but, above code incorrect ; want follows;
<connectionstrings> <add name="sdbconnection" providername="system.data.sqlclient" connectionstring="data source=(localdb)\v11.0;attachdbfilename=|datadirectory|ppldb.mdf;integrated security=true" /> </connectionstrings>
but datadirectory
? specify ?
what name="sdbconnection"
? can give name want ?
first question quoting msdn:
the |datadirectory| portion of connection string specifies mdf file located inthe app_data directory
moreover can change using following function:
appdomain.currentdomain.setdata("datadirectory", "d:\database");
second question name="sdbconnection" allows use specified conection string. in code can write:
string connectionstring = configurationmanager.connectionstrings["sdbconnection"].connectionstring;
to acces connection string
Comments
Post a Comment