opening a connection to a database

Dami alwed

New Member
I have read an article that explains how to open a db connection in C# as:<BR><BR>cont string strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\DataGrocerToGo.mdb";<BR><BR>OleDbConnection objConn = new OleDbConnection(strConnString);<BR><BR>objConn.Open();<BR><BR><BR>// Now, my question is, Can I store the objConn information in a globally accessible location (either in a class or in the global.asax) so that anywhere in my application, I can open a connection to the database simply by using:<BR><BR>objConn.Open();Hi,<BR>you can do this in the web.config file, which I think you would put in the application directory(check this)....you can specify it like you would an application or session variable in there. Here is an example I have used...(not written by me<BR><BR><configuration><BR><BR> <!-- store the database connection info here --><BR><BR> <appSettings><BR> <add key="DSN"value=http://aspmessageboard.com/archive/index.php/"server=localhost;uid=sa;pwd=;database=Northwind" /><BR> </appSettings><BR><BR></configuration><BR><BR>**********<BR><BR>you can then call the value like this in your ASP.NET page(this is using VB....C# may vary)<BR><BR>DSN = ConfigurationSettings.AppSettings("DSN")<BR><BR>good luck!<BR><BR>Neil
 
Back
Top