J
Jaime Stuardo
Hi all..
I have created a business logic component that is used from my ASP.NET
webform. It works, but connection string to the database is hard coded, as
in this method :
public DataSet GetCategories()
{
SqlConnection conn = new SqlConnection("Data Source=DEVSERVER;Initial
Catalog=XXXX;User ID=X;Password=Y");
SqlDataAdapter adapter = new SqlDataAdapter("SELECT CAT_ID, CAT_NOM FROM
CATEGORIA ORDER BY CAT_NOM", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
I need to know what is the best way to pass the connection string that is
present in the web.config file. I tried using a constructor in that business
class but with no success. Also I have read that ObjectDataSource uses
stateless components so I think the usage of properties isn't allowed here.
The question is, the only solution I could implement is passing the
connection string as a parameter to GetCategories? is there another one?
Since this method resides in a DLL, I cannot use ConnectionManager class to
access web.config file.
Thanks a lot
Jaime
I have created a business logic component that is used from my ASP.NET
webform. It works, but connection string to the database is hard coded, as
in this method :
public DataSet GetCategories()
{
SqlConnection conn = new SqlConnection("Data Source=DEVSERVER;Initial
Catalog=XXXX;User ID=X;Password=Y");
SqlDataAdapter adapter = new SqlDataAdapter("SELECT CAT_ID, CAT_NOM FROM
CATEGORIA ORDER BY CAT_NOM", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
I need to know what is the best way to pass the connection string that is
present in the web.config file. I tried using a constructor in that business
class but with no success. Also I have read that ObjectDataSource uses
stateless components so I think the usage of properties isn't allowed here.
The question is, the only solution I could implement is passing the
connection string as a parameter to GetCategories? is there another one?
Since this method resides in a DLL, I cannot use ConnectionManager class to
access web.config file.
Thanks a lot
Jaime