Connection String - Oracle & MS SQL
I'm connecting to Microsoft SQL and Oracle database. To connect to SQL , I have this code in my web.config
Code:
<connectionStrings>
<add name="BITESampleDBConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Inside my application I'm using this code to connect to oracle :
Code:
Try
conn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=XE ;User ID=username;Password=password"
conn.Open()
Catch
'DISPLAYING CONNECTION STATUS
'----------------------------
Response.Write("Unable to connect to Database ")
Response.Write("<BR>")
Response.Write(Err.Description)
Response.End()
End Try
now , because I need to connect to oracle alot , can add something to my web.config , instead of using that code to connect to oracle?
What's your advise
Re: Connection String - Oracle & MS SQL
I would suggest pulling the connection string right from the web.config like this:
Code:
dim strConn as string = System.Configuation.ConfigurationManager.ConnectionStrings.item("BITESampleDBConnectionString1")
It's much cleaner and you could even initialize this globally so you don't have to keep doing this.
Re: Connection String - Oracle & MS SQL
You'll need to change the client namespace you're using for your objects though. For SQL, it was System.Data.SqlClient, but that's only for SQL Server.