I am attempting to simply connect to the database and retrieve a few records. Below is the code I am using
<script runat="server">
Sub Page_Load(Sender As Object, E as EventArgs)
If Not IsPostBack Then
Dim OracleConn As OracleConnection=New OracleConnection()
OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;"
OracleConn.Open()
Dim NameDS As Dataset=New Dataset
Dim GetNamesCommand As OleDbCommand=New OleDbCommand
GetNamesCOmmand.CommandText="Select * from tblPerson"
GetNamesCommand.Connection=OracleConn
Adapter.SelectCommand=GetNamesCommand
Adapter.SelectCommand.Connection.Open
Adapter.Fill(NamesDS,"tblPerson")
dgNames.DataSource=NamesDS.Tables("tblPerson")
dgNames.Databind
End If
</script>
Test
<form runat="server">
</form>
When I attempt to run the page I get an error... Description: An error occurred during the compilation of a resource required to service this request.
Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30002: Type 'OracleConnection' is not defined. Source Error: Line 7: If Not IsPostBack Then Line 8: Line 9: Dim OracleConn As OracleConnection=New
OracleConnection() Line 10: Line 11: OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;" with Line 9 highlighted. I have downloaded and installed the oracle.net provider from http://www.microsoft.com/downloads/details.aspx?FamilyID=4f55d429-17dc-45ea-bfb3-076d1c052524&DisplayLang=en
I can't figure out what is wrong. Any help would be greatly appreciated.
If Not IsPostBack Then
'Dim OracleConn As OracleConnection = New OracleConnection
Dim OracleConn As New OracleConnection()
OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;"
'OracleConn.Open() ' If you open it you must close it! it is Not Needed the dataadapter will open/close your connection for you if it is already closed
'Dim NameDS As DataSet = New DataSet
Dim NamesDs As New DataSet()
'Dim GetNamesCommand As OleDbCommand = New OleDbCommand
' Are you using OLEDB or Oracle Here?
'Use the following line
Dim GetNamesCommand As New OracleCommand()
GetNamesCOmmand.CommandText="Select * from tblPerson"
GetNamesCommand.Connection = OracleConn
' Adapter in not defined
' use the following line
Dim Adapter As New OracleDataAdapter(GetNamesCommand)
' Note to Link the DataAdapter to the Command Object
Adapter.SelectCommand = GetNamesCommand
'Adapter.SelectCommand.Connection.Open() 'Not Needed see above comment if used be sure to close()
Adapter.Fill(NamesDs, "tblPerson")
dgNames.DataSource = NamesDs.Tables("tblPerson")
dgNames.DataBind()
End If
I've changed my file with your suggestions to the code below. However, I'm still getting the error Compiler Error Message: BC30002: Type 'OracleConnection' is not defined. It's almost as if the System.Data.OracleClient isn't being imported or registered as
a class. I have uninstalled and reinstalled the Oracle .Net provider and still have not be able to get this to work. On a whim, I installed the asp.matrix application. With it comes a class browser. I looked through the classes and I was surprised to see that
the System.Data.Oracle.Client is not listed. However, when I look at the asp.net wizard/config apps in control panel-->administrative tools I can clearly see the System.Data.Oracle.Client class. I'm completely confused about what is wrong.
<script runat="server">
Sub Page_Load(Sender As Object, E as EventArgs)
If Not IsPostBack Then
Dim OracleConn As New OracleConnection()
OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;"
Dim NamesDs As New DataSet()
Dim GetNamesCommand As New OracleCommand()
GetNamesCOmmand.CommandText="Select * from tblPerson"
GetNamesCommand.Connection = OracleConn
Dim Adapter As New OracleDataAdapter(GetNamesCommand)
' Note to Link the DataAdapter to the Command Object
Adapter.SelectCommand = GetNamesCommand
Adapter.Fill(NamesDs, "tblPerson")
dgNames.DataSource = NamesDs.Tables("tblPerson")
dgNames.DataBind()
End If
End Sub
</script>
justjoehere I ran the code and it worked fine. I assume you are using the web matrix there must be an option where you add the physical path of the data provider ie. C:\ProgramFiles\Microsoft.NET\OracleClient.Net\System.Data.OracleClient.dll to the refences
so the system know where to locate this. Try looking it up in you help. Hope this works for you -Tiny
Thank you very much for all your input. Based on your suggestion, the following code works (but see steps at end I had to take as well.)
<script runat="server">
Sub Page_Load(Sender As Object, E as EventArgs)
If Not IsPostBack Then
Dim ConnectionString As String
Dim OracleConn As New OracleConnection()
Dim Adapter As New OracleDataAdapter()
Dim NamesDS As Dataset=New Dataset
OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=deadbolt;"
'OracleConn.Open()
Adapter.SelectCommand=New OracleCommand("Select * from tblPerson")
Adapter.SelectCommand.Connection=OracleConn
Adapter.SelectCommand.Connection.Open
Adapter.Fill(NamesDS,"tblPerson")
dgNames.DataSource=NamesDS.Tables("tblPerson")
dgNames.Databind
End If
End Sub
</script>
Login
<form runat="server">
</form>
After I made your suggested changes, I also had to reinstall the oracle 9i client. It seems that the first time I
installed the oracle client the oci.dll file was missing from the Ora\bin directory of my installation. I believe this happened because I upgraded from 8i to 9i. In any event, getting the right oci.dll in the right directory helped. For other users here are
some other things to check 1) oci.dll is in your directoy (oracle\ora\bin) 2) your path statement includes the path to the oci.dll (usually requires a reboot to take effect) 3) follow the suggestions at http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q255084&LN=EN-US
, specifically adding privledges to the oracle directory for ASPNET, IWAM, IUSER (requires an IIS restart) 4) Manually reference the system.data.oracleclient.dll as in this example.
Thank you. I have been having the same problems and the line which reads: CompilerOptions='/R:"C:\Program Files\Microsoft.NET\OracleClient.Net\System.Data.OracleClient.dll"' has finally enabled me to successfully connect to oracle. Having said this, I would
like my connection information in a code behind .vb page. How do I the above line inside a .vb page? Any advice would be greatly appreciated.
justjoehere
Member
15 Points
3 Posts
aspx beginner having problems retrieving data from Oracle 9i
Mar 11, 2003 01:19 PM|LINK
<script runat="server"> Sub Page_Load(Sender As Object, E as EventArgs) If Not IsPostBack Then Dim OracleConn As OracleConnection=New OracleConnection() OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;" OracleConn.Open() Dim NameDS As Dataset=New Dataset Dim GetNamesCommand As OleDbCommand=New OleDbCommand GetNamesCOmmand.CommandText="Select * from tblPerson" GetNamesCommand.Connection=OracleConn Adapter.SelectCommand=GetNamesCommand Adapter.SelectCommand.Connection.Open Adapter.Fill(NamesDS,"tblPerson") dgNames.DataSource=NamesDS.Tables("tblPerson") dgNames.Databind End If </script>When I attempt to run the page I get an error... Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30002: Type 'OracleConnection' is not defined. Source Error: Line 7: If Not IsPostBack Then Line 8: Line 9: Dim OracleConn As OracleConnection=New OracleConnection() Line 10: Line 11: OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;" with Line 9 highlighted. I have downloaded and installed the oracle.net provider from http://www.microsoft.com/downloads/details.aspx?FamilyID=4f55d429-17dc-45ea-bfb3-076d1c052524&DisplayLang=en I can't figure out what is wrong. Any help would be greatly appreciated.Test
<form runat="server"> </form>TinyPond
Member
739 Points
228 Posts
Re: aspx beginner having problems retrieving data from Oracle 9i
Mar 13, 2003 04:31 PM|LINK
If Not IsPostBack Then 'Dim OracleConn As OracleConnection = New OracleConnection Dim OracleConn As New OracleConnection() OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;" 'OracleConn.Open() ' If you open it you must close it! it is Not Needed the dataadapter will open/close your connection for you if it is already closed 'Dim NameDS As DataSet = New DataSet Dim NamesDs As New DataSet() 'Dim GetNamesCommand As OleDbCommand = New OleDbCommand ' Are you using OLEDB or Oracle Here? 'Use the following line Dim GetNamesCommand As New OracleCommand() GetNamesCOmmand.CommandText="Select * from tblPerson" GetNamesCommand.Connection = OracleConn ' Adapter in not defined ' use the following line Dim Adapter As New OracleDataAdapter(GetNamesCommand) ' Note to Link the DataAdapter to the Command Object Adapter.SelectCommand = GetNamesCommand 'Adapter.SelectCommand.Connection.Open() 'Not Needed see above comment if used be sure to close() Adapter.Fill(NamesDs, "tblPerson") dgNames.DataSource = NamesDs.Tables("tblPerson") dgNames.DataBind() End If:-) -Tinyjustjoehere
Member
15 Points
3 Posts
Re: aspx beginner having problems retrieving data from Oracle 9i
Mar 13, 2003 04:45 PM|LINK
<script runat="server"> Sub Page_Load(Sender As Object, E as EventArgs) If Not IsPostBack Then Dim OracleConn As New OracleConnection() OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=unreplicated;" Dim NamesDs As New DataSet() Dim GetNamesCommand As New OracleCommand() GetNamesCOmmand.CommandText="Select * from tblPerson" GetNamesCommand.Connection = OracleConn Dim Adapter As New OracleDataAdapter(GetNamesCommand) ' Note to Link the DataAdapter to the Command Object Adapter.SelectCommand = GetNamesCommand Adapter.Fill(NamesDs, "tblPerson") dgNames.DataSource = NamesDs.Tables("tblPerson") dgNames.DataBind() End If End Sub </script>Test
<form runat="server"> </form>TinyPond
Member
739 Points
228 Posts
Re: aspx beginner having problems retrieving data from Oracle 9i
Mar 14, 2003 01:37 AM|LINK
justjoehere
Member
15 Points
3 Posts
Re: aspx beginner having problems retrieving data from Oracle 9i
Mar 14, 2003 05:44 PM|LINK
<script runat="server"> Sub Page_Load(Sender As Object, E as EventArgs) If Not IsPostBack Then Dim ConnectionString As String Dim OracleConn As New OracleConnection() Dim Adapter As New OracleDataAdapter() Dim NamesDS As Dataset=New Dataset OracleConn.ConnectionString="user id=unreplicated;password=joe;Data Source=deadbolt;" 'OracleConn.Open() Adapter.SelectCommand=New OracleCommand("Select * from tblPerson") Adapter.SelectCommand.Connection=OracleConn Adapter.SelectCommand.Connection.Open Adapter.Fill(NamesDS,"tblPerson") dgNames.DataSource=NamesDS.Tables("tblPerson") dgNames.Databind End If End Sub </script>After I made your suggested changes, I also had to reinstall the oracle 9i client. It seems that the first time I installed the oracle client the oci.dll file was missing from the Ora\bin directory of my installation. I believe this happened because I upgraded from 8i to 9i. In any event, getting the right oci.dll in the right directory helped. For other users here are some other things to check 1) oci.dll is in your directoy (oracle\ora\bin) 2) your path statement includes the path to the oci.dll (usually requires a reboot to take effect) 3) follow the suggestions at http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q255084&LN=EN-US , specifically adding privledges to the oracle directory for ASPNET, IWAM, IUSER (requires an IIS restart) 4) Manually reference the system.data.oracleclient.dll as in this example.Login
<form runat="server"> </form>evanr
Member
5 Points
1 Post
Re: aspx beginner having problems retrieving data from Oracle 9i
Oct 02, 2003 11:02 AM|LINK
mcguiliver
Member
30 Points
10 Posts
Re: aspx beginner having problems retrieving data from Oracle 9i
Aug 18, 2010 05:53 AM|LINK
This is a good read if you want to learn how to connect and use oracle db http://www.codeproject.com/KB/database/C__Instant_Oracle.aspx
hope this helps.
programming database access