Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i create 3 tier architecture web application with 3 layer in 3 different project:
i store connection string in presentation layer web.config file

i want to access connection string in data access layer;

use this code;
ConfigurationManager.ConnectionStrings("sqlcon").ConnectionString

bt it give error
Posted
Comments
Ranjan.D 27-Oct-13 10:45am    
Fist please make sure you have the correct connection string key i.e sqlcon. When you reference the data access layer with in your web project you should be able to access this connection string..

You are just saying getting an error, but what exactly the error is ?
priyanshbhaliya 27-Oct-13 11:03am    
it give error on configrationManager
Sampath Lokuge 27-Oct-13 11:12am    
Can you give the details of connection string on web.config file (put it on your question) and complete error or stack trace ?
PIEBALDconsult 27-Oct-13 11:53am    
"i store connection string in presentation layer"

Wrong, only the Data Access Layer needs that; no other layer should have access to it.
priyanshbhaliya 27-Oct-13 12:54pm    
web.config file is in presentation layer...

1 solution

In your case You need to add System.Configuration component(.NET framework component) reference from your Data Access Project. When you add reference with in this project, data access layer ConfigurationManager Class will work and able to read UI project Web.Config File and get your connection string value if you properly register/add connection string value with key "sqcon" there.
 
Share this answer
 
Comments
priyanshbhaliya 28-Oct-13 12:24pm    
connectstring:"Server=priyansh; Initial Catalog=report;User ID=; Pwd="
my code :
Imports System.Data.SqlClient
Imports System.Configuration
Dim strconn As String
strconn = ConfigurationManager.ConnectionStrings("sqlcon").ConnectionString

error at here :configurationManager
S. M. Ahasan Habib 28-Oct-13 12:57pm    
what type of error you found. Is it compile time or run time? Please write detail about errors. for example if it is compile time then what compiler says. if it is run time then what exception it throws and exception message etc.
Member 13552848 2-Dec-17 2:59am    
please help me out m using 3tier and in my dal i found a command type error

public virtual int Insert(PAL_registration pl)
{


SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand("Pro_registration", conn);

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName",pl.UserName);
cmd.Parameters.AddWithValue("@Password", pl.Password);
cmd.Parameters.AddWithValue("@Email", pl.Email);
cmd.Parameters.AddWithValue("SecurityAnswer", pl.SecurityAnswer);

try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch
{ }

}

}

in connection string m using sqlhelper class file bt connection is nt established
priyanshbhaliya 9-Dec-17 3:52am    
can you please share connection code and connectionstring?
Member 13975474 8-Jan-21 5:41am    
I am using a Three-tier type application. 1st is a presentation layer that has forms. Then is a Web API followed by Data Access Layer. My connection string is in web-config of the Data Access layer. And I am trying to access string in a C# class that is also in Data Access Layer and contains all the procedure calls in various functions. I cannot access connection string and it shows null reference error

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