Petiedawgs
asked on
OleDB Connection Command and Reader, complication on Making it work!
Hi trying to Open a connection, Execute a select command and populate a datagrid with information from an access database. The code compiles but I do not get any output. All I have is one datagrid to be populated. Please look at my code and let me know what I need to change or what I am doing wrong? Thanks every1!
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.Ole DB" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx. vb" Inherits="localhost.WebFor m1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScri pt">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="vb" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim LinksConnection As OleDBConnection
Dim LinksCommand As OleDbCommand
LinksConnection = New OleDbConnection ("Provider=Microsoft.Jet.O leDB.4.0;s erver=loca lhost;uid= Admin;pwd= ;database= C:\Inetpub \wwwRoot\A uto.mdb")
LinksCommand = New OleDBCommand("select * from Links", LinksConnection)
LinksConnection.Open()
Dim dr As OleDBDataReader = LinksCommand.ExecuteReader ()
dgLinks.DataSource = dr
dgLinks.DataBind()
LinksConnection.Close()
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgLinks" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 72px" runat="server"
Height="336px" Width="368px"></asp:datagr id></form>
</body>
</HTML>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.Ole
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScri
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="vb" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim LinksConnection As OleDBConnection
Dim LinksCommand As OleDbCommand
LinksConnection = New OleDbConnection ("Provider=Microsoft.Jet.O
LinksCommand = New OleDBCommand("select * from Links", LinksConnection)
LinksConnection.Open()
Dim dr As OleDBDataReader = LinksCommand.ExecuteReader
dgLinks.DataSource = dr
dgLinks.DataBind()
LinksConnection.Close()
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgLinks" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 72px" runat="server"
Height="336px" Width="368px"></asp:datagr
</body>
</HTML>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the error happens at the linksconnection.open()
This error could be due to so many reasons. First I try to get tehe latest MDAC from microsoft. Then I look at the following article
http://support.microsoft.com/default.aspx?scid=kb;EN-US;283881
Before all this if you do not have a password for your Admin account, please set it to empty string as follows
LinksConnection = New OleDbConnection("Provider= Microsoft. Jet.OleDB. 4.0;server =localhost ;uid=Admin ;pwd='';da tabase=C:\ Inetpub\ww wRoot\Auto .mdb")
If none of this solves, I would go do some googling as this is a very common error
http://support.microsoft.com/default.aspx?scid=kb;EN-US;283881
Before all this if you do not have a password for your Admin account, please set it to empty string as follows
LinksConnection = New OleDbConnection("Provider=
If none of this solves, I would go do some googling as this is a very common error
ASKER
thanks im working on it!!!
ASKER
Man I dont think im going to get too far in this....I have no registry entry for MS Jet 4.0. I tried reinstalling MS Office to try and get that entry back but i dont have the cd for it. Im basically stuck in a rock and a hard place.
did you try putting blank empty string for pwd as i suggested
ASKER
Im gonna let this one go and try some other options. I am actually going to Reimage my computer right now and hope everything gets back in order. Thanks ryerras and joeisanerd. I think I can figure it out if i can get the MS Jet registry back in order.
ASKER
Yes I did I put the blank password.
ok good luck then. As soon as you finish figuring out, come back and close this question, or if you think any of our comments helped, close it right away, rather than leaving the question open forever
If this is the only problem you are having I think reimaging your machine is bit extreme. Looking at your connection string it doesn't look right. Here is a connection string for accessing an access file that I know works
This is taken straight from a program I made and it's in C#
//Setup Ado connection to it
mdbConnString = "Provider=Microsoft.Jet.OL EDB.4.0;";
mdbConnString += "Data Source="+openFileDialog1.F ileName+"; ";
mdbConnString += "Password=;User ID=Admin;Jet OLEDB:Database Password=;";
mdbConnString += "Mode=Share Deny None;Jet OLEDB:Database Locking Mode=1;";
I don't believe that access needs the server= or the database= tag instead use Data Source=
This is taken straight from a program I made and it's in C#
//Setup Ado connection to it
mdbConnString = "Provider=Microsoft.Jet.OL
mdbConnString += "Data Source="+openFileDialog1.F
mdbConnString += "Password=;User ID=Admin;Jet OLEDB:Database Password=;";
mdbConnString += "Mode=Share Deny None;Jet OLEDB:Database Locking Mode=1;";
I don't believe that access needs the server= or the database= tag instead use Data Source=
Howdy.
This may be cheating (but it works for me). Whenever I have a connection string problem, I let the IDE generate the connection string for me, then copy it into my code. Just setup a dummy connection using the ISE and then copy the connection string out of the connection's properties. At least this way you can test it and rule out whether the string itself is the issue.
Also, this won't help your error issue, but you can slightly optimize your code by cutting the datareader object out all together by assigning the LinksCommand.ExecuteReader directly to the dgLinks.DataSource parameter...
dgLinks.DataSource = LinksCommand.ExecuteReader
dgLinks.DataBind
At the very least, it's one less object to worry about...just my 2 cents!
This may be cheating (but it works for me). Whenever I have a connection string problem, I let the IDE generate the connection string for me, then copy it into my code. Just setup a dummy connection using the ISE and then copy the connection string out of the connection's properties. At least this way you can test it and rule out whether the string itself is the issue.
Also, this won't help your error issue, but you can slightly optimize your code by cutting the datareader object out all together by assigning the LinksCommand.ExecuteReader
dgLinks.DataSource = LinksCommand.ExecuteReader
dgLinks.DataBind
At the very least, it's one less object to worry about...just my 2 cents!
ASKER
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbExc
Source Error:
Line 18: LinksConnection = New OleDbConnection("Provider=
Line 19: LinksCommand = New OleDBCommand("select * from Links", LinksConnection)
Line 20: LinksConnection.Open()
Line 21:
Line 22: Dim dr As OleDBDataReader = LinksCommand.ExecuteReader