DB Connection

partha.majumdar

Active member
Joined
Aug 13, 2006
Messages
33
Location
Kolkata
Programming Experience
10+
Dear Sir,

I am new to MS Visual Studio 2010 and am a bit out of touch with ASP.Net.

I have a ORACLE Database and the database name is QADB and the user name is partha with password partha.

What entry do I need making in the web.config to be able to connect to this database.



I understand that this is very basic. However, I would be extremely grateful for your help.

Regards,
Partha
 
The entry in the web.config file is just the connection string. You still need to write code to use that connection string to make a connection. With regards to connection strings, visit ConnectionStrings.com to get the appropriate format. In your project, use the Settings page of the project properties to add an entry of type (Connection string) to your config file.
 
Thanks.

I have added the following to the web.config.
<add name="OracleDataProvider" providerName="Oracle.DataAccess.Client" connectionString="User ID=partha;Password=partha;Data Source=qadb"/>


Now how do I read this into the application and connect to the database?

Regards,
Partha
 
Dear Sir,
Please pardon my ignorance. I could not understand the reply as I did not find the class WebConfiguration Manager.

Below is the code I used to connect to the DB.
============================================================
'Open a Oracle Connection
Dim str_Connection As String = "User ID=partha;Password=partha;Data Source=qadb"
Dim obj_OracleConnection As OracleConnection = New OracleConnection(str_Connection)

Try
obj_OracleConnection.Open()
Response.Write("Connected to Oracle" + obj_OracleConnection.ServerVersion)
=========================================

Now, my purpose is to have the contents of the connection string in the web.config and read it in the application and connect to the DB and not have the same coded in the code.

Please help.

REgard
 
Dear Sir,

I have found the solution.

I used the following:
=====================
Dim str_Connection As String = ConfigurationManager.ConnectionStrings.Item("OracleDataProvider").ConnectionString
=====================

It works.

Thanks.

Regards,
Partha
 
Dear Sir,

I put he code for connecting to the database in global.ascx. It is able to connect to the database. However, I want that if it cannot connect to the database, it should not proceed to the application. Instead, it should an error page.

I am unable to use REsponse.REdirect().

How can this be achieved?

My Code:
=====================
Public Class Global_asax
Inherits System.Web.HttpApplication
Public Shared i_obj_OracleConnection As OracleConnection

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Dim l_str_Connection As String = Nothing

'Open a Oracle Connection
l_str_Connection = ConfigurationManager.ConnectionStrings.Item("OracleDataProvider").ConnectionString
i_obj_OracleConnection = New OracleConnection(l_str_Connection)

Try
i_obj_OracleConnection.Open()

Catch ex As Exception
'TODO: What to do???
End Try
End Sub
=========================





Thanks and Regards,
Partha
 
Back
Top