asp.net oracle connection in code behind

I am trying to connect to oracle on visual web developer express edition 2008 in code behind without using wizards.

I've read the posts but cannot solve the problem below.

When I use the wizards, i connect fine to Oracle.  Below is the web config file with the connection string.

  But when i try and do a code behind and do my own database connection, i get the message

"System.Data.OracleClient' is a namespace and cannot be used as an expression'.

 I also get the same error when i try odbc.

Here is the code:

     Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim conn_string As String = "<%$ ConnectionStrings:ConnectionString %>"
   
        Using System.Data.OracleClient
 
            OracleConnection(oracleConn = New OracleConnection())
            oracleConn.ConnectionString = "user id=www6026 Data source=edwdev password=Saddy1942"
            oracleConn.Open()
 
             End Using
 
    End Sub
***********************
Here is the connection string from web.config:

        <connectionStrings>
                <add name="ConnectionString" connectionString="Data Source=edwdev;Persist Security Info=True;User ID=www6026;Password=Saddy1942;Unicode=True" providerName="System.Data.OracleClient"/>
        </connectionStrings>
 
 
 
agw47aaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jinalCommented:
Also you have to put

Imports System.Data.OracleClient at top of your code behind file

I think you are using vb.net so you have to use Imports System.Data.OracleClient .

 




 
  Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim conn_string As String =  System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
            Dim  oracleConn as System.Data.OracleClient.OracleConnection = New OracleConnection()
            oracleConn.ConnectionString = conn_string
            oracleConn.Open()
 
             End Using
 
    End Sub

Open in new window

0
agw47aaAuthor Commented:
I have already coded the import.  I should have included the entire code behind.  Here it is: Please advise.

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Data.OracleClient
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim instance As SqlCommand
 
      Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim conn_string As String = "<%$ ConnectionStrings:ConnectionString %>"
        '      Me.ReadOrderData(conn_string)
 
        Using System.Data.OracleClient
 
            OracleConnection(oracleConn = New OracleConnection())
            oracleConn.ConnectionString = "user id=waq6026 Data source=edwdev password=Sandy1942"
            oracleConn.Open()
 
             End Using
 
    End Sub
End Class
 
0
jinalCommented:

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Data.OracleClient
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim instance As SqlCommand
 
      Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim conn_string As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString")
        '      Me.ReadOrderData(conn_string) 
OracleConnection(oracleConn = New OracleConnection())
oracleConn.ConnectionString = "Data Source=edwdev;Persist Security Info=True;User ID=www6026;Password=Saddy1942;Unicode=True"
oracleConn.Open()
 
             End Using
 
    End Sub
End Class
 

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

jinalCommented:

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Data.OracleClient
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim instance As SqlCommand
 
      Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim conn_string As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString")
        '      Me.ReadOrderData(conn_string) 
Dim oracleConn  as OracleConnection  = New OracleConnection()
oracleConn.ConnectionString = "Data Source=edwdev;Persist Security Info=True;User ID=www6026;Password=Saddy1942;Unicode=True"
oracleConn.Open()
 
             End Using
 
    End Sub
End Class

Open in new window

0
agw47aaAuthor Commented:
Thanks.. not quite right yet.

First, there is no USING statement but there is an END USING in the code above.  I put the USING statement in.. I still get two errors.

 
Error   1       Value of type 'System.Configuration.ConnectionStringSettings'
cannot be converted to 'String'.
        13      37      C:\...\login_screen\
 
Error   2       'System.Data.OracleClient' is a namespace and
cannot be used as an expression.
        14      15      C:\...\login_screen\
 ***********************************************************************************
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Data.OracleClient
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim instance As SqlCommand
 
    Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim conn_string As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString")
        Using System.Data.OracleClient
 
            OracleConnection(oracleConn = New OracleConnection())
            oracleConn.ConnectionString = "Data Source=edwdev;Persist Security Info=True;User ID=www6026;Password=Saddy1942;Unicode=True"
            oracleConn.Open()
 
        End Using
 
    End Sub
End Class


0
jinalCommented:

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Data.OracleClient
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim instance As SqlCommand
 
      Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim conn_string As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        '      Me.ReadOrderData(conn_string) 
Dim oracleConn  as OracleConnection  = New OracleConnection()
oracleConn.ConnectionString = "Data Source=edwdev;Persist Security Info=True;User ID=www6026;Password=Saddy1942;Unicode=True"
oracleConn.Open()
 
             End Using
 
    End Sub
End Class

Open in new window

0
agw47aaAuthor Commented:
Thanks to your help, I got it to work.  I also added a data reader and select statement to retrieve some data.  Here is the code with some comments:

' this is the base connection and simple SELECT command
' connects to oracle, and then reads a table and displays the first column in the msgbox.
' there is also logic here to see if any records were returned
'i didn't get the console command to work
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Data.OracleClient
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim instance As SqlCommand
 
    Protected Sub Login_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login_Button.Click
        Dim a1 As Integer
 
        Dim oracleConn As OracleConnection = New OracleConnection()
        '  Dim select_Text As String = "select a1, a2 from abc where a1 = 57575"
        Dim select_Text As String = "select a1, a2 from abc"
        Dim cmd As OracleCommand = New OracleCommand()
        a1 = 1
        oracleConn.ConnectionString = "Data Source=edwdev;Persist Security Info=True;User ID=scott;Password=tiger;Unicode=True"
        oracleConn.Open()
        cmd.CommandType = CommandType.Text
        cmd.Connection = oracleConn
        cmd.CommandText = select_Text
 
        '  MsgBox("HELLO ARNIE")
 
        Dim reader As OracleDataReader = cmd.ExecuteReader()
 
        Do While reader.Read()
            MsgBox(reader(0))
            a1 = a1 + 1
            Console.WriteLine(String.Format("{0}, {1}", reader(0), reader(1)))
        Loop
        reader.Close()
        If a1 = 1 Then
            MsgBox("No records found")
        End If
    End Sub
End Class
0
jinalCommented:
So your work in done ?

If you get solution then please select the solution from comment.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
agw47aaAuthor Commented:
Great help from Jinal.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.