|
hi master
sir i have oracle database how i connect my oracle with asp.net
and i not want new connection code in every page my need is
i deffine connection code one time in first page and use in all page
such as vb6
please give me idea
thanks
aamir
|
|
|
Hi aamir,
You need to define you connection string in Web.Config file.
-Amit
|
|
|
Yes, u can achieve this using web.config file.. The following code would be helpful to understand...
In web.cofig
============
You can define key pair value and use it in your application. Its available in entire application.
// Adding key = ConnectionString contains database connection
<configuration>
<appSettings>
<add key="ConnectionString" value="Data Source=intranet-xp;Initial Catalog=xysz;User Id=myself;Password=joke;" />
</appSettings>
<configuration>
In aspx.cs page
===============
1. using System.Configuration; namespace to fetch config file values.
2. Use ConfigurationSettings.AppSettings.AppSettings[key]; to fetch particular key value.
To fetch the above connection string...
OracleConnection MyConnection = new OracleConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
|
|
|
|
|
|
|
// |