Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using web application
in Appcode->DAL-> class DBbridge.cs

C#
public static string DBConnection()
       {
           try
           {
               return System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];

           }
           catch (Exception ce)
           {

              throw new ApplicationException("Unable to get DB Connection string from Config File. Contact Administrator" + ce);
           }
       }

while in web.config
XML
<connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=.;Integrated Security=true;Initial Catalog=szicExam" providerName="System.Data.SqlClient"/>
  </connectionStrings>


but i am getting this error
Value cannot be null.
Parameter name: connectionString



C#
Line 490:        public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
Line 491:        {
Line 492:            if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString");
Line 493:
Line 494:            // Create & open a SqlConnection, and dispose of it after we are done

Source File: f:\My Final Project with Data\MCQs Test System\MCQs Test System\App_Code\DAL\SQLHelper.cs    Line: 492 
Posted

use this
System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"];

in place of
System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
 
Share this answer
 
Comments
Muhamad Faizan Khan 26-Apr-14 5:07am    
also add toString();
Try this
string conStr = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
 
Share this answer
 
sqlconnection con=new sqlconnection(system.configuraton.configurationmanager.appsetting["ConnectionString"].tostring());

try this.........
 
Share this answer
 
For accessing connection string or database with reference to connection string mentioned in web.config file you can make use of SqlConnectionstringBuilder class.

Refer below links..

stBring[^]
 
Share this answer
 
string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900