Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Newbie - Connecting to Database


Message #1 by "Haydn Williams" <haydnw@y...> on Thu, 2 Jan 2003 23:06:40
Hi,

I'm trying to use ASP.NET for the first time to connect to a database. 
It's an Access database at c:\database.mdb. I'm using the following code 
in my Web Form:

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script runat="server">

    Sub Page_Load()
    Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
    strConnString += "Data Source=c:\database.mdb"
    data_src.text = strConnString
    
    Dim objConnectionObject As New OledbConnection(strConnString)
    
    try
    objConnectionObject.Open()
    objConnectionObject.Close()
    catch e as exception
    
    con_open.text = "Connection failed to open"
    con_close.text =e.ToString()
    End try
    
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:Label id="data_src" runat="server">Label</asp:Label>
            <asp:Label id="con_open" runat="server">Label</asp:Label>
            <asp:Label id="con_close" runat="server">Label</asp:Label>
        </p>
    </form>
</body>
</html>


Which produces the following results:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb 


Connection failed to open 


System.Data.OleDb.OleDbException: Could not find file 'c:\database.mdb'. 
at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at 
System.Data.OleDb.OleDbConnection.InitializeProvider() at 
System.Data.OleDb.OleDbConnection.Open() at ASP.database_aspx.Page_Load() 


Now, I understand what it is saying - that's pretty obvious. What I'm 
wondering is if anyone can give me any idea why it might not be finding 
the file. I started with it in a folder on the HDD, and moved it to the 
root to be sure it wasn't just my typing! Anyone got any ideas for a 
newbie? Many thanks.

H
Message #2 by "Alex Smotritsky" <alex.smotritsky@v...> on Thu, 2 Jan 2003 18:00:06 -0500
In vs.net you can just drag the db from the server explorer on to the
web form and a connection object will be generated for you.


-----Original Message-----
From: Haydn Williams [mailto:haydnw@y...] 
Sent: Thursday, January 02, 2003 11:07 PM
To: aspx_beginners
Subject: [aspx_beginners] Newbie - Connecting to Database


Hi,

I'm trying to use ASP.NET for the first time to connect to a database. 
It's an Access database at c:\database.mdb. I'm using the following code

in my Web Form:

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script runat="server">

    Sub Page_Load()
    Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
    strConnString += "Data Source=c:\database.mdb"
    data_src.text = strConnString
    
    Dim objConnectionObject As New OledbConnection(strConnString)
    
    try
    objConnectionObject.Open()
    objConnectionObject.Close()
    catch e as exception
    
    con_open.text = "Connection failed to open"
    con_close.text =e.ToString()
    End try
    
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:Label id="data_src" runat="server">Label</asp:Label>
            <asp:Label id="con_open" runat="server">Label</asp:Label>
            <asp:Label id="con_close" runat="server">Label</asp:Label>
        </p>
    </form>
</body>
</html>


Which produces the following results:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb 


Connection failed to open 


System.Data.OleDb.OleDbException: Could not find file 'c:\database.mdb'.

at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at 
System.Data.OleDb.OleDbConnection.InitializeProvider() at 
System.Data.OleDb.OleDbConnection.Open() at
ASP.database_aspx.Page_Load() 


Now, I understand what it is saying - that's pretty obvious. What I'm 
wondering is if anyone can give me any idea why it might not be finding 
the file. I started with it in a folder on the HDD, and moved it to the 
root to be sure it wasn't just my typing! Anyone got any ideas for a 
newbie? Many thanks.

H

Message #3 by Setsiri Thanvarakul <setsiri@y...> on Thu, 2 Jan 2003 20:12:07 -0800 (PST)
Hi, 
just add "\"  at c:\\database.mdb

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
Message #4 by Colin.Montgomery@C... on Fri, 3 Jan 2003 10:34:08 -0000
I have a feeling that you can't name a database "database.mdb".  Try
changing it's name (and therefore the connection string) and see if it
helps.

Surely the database must have a purpose, such as customer orders or
something?  Why not call it something more meaningful.

HTH,
Col

-----Original Message-----
From: Haydn Williams [mailto:haydnw@y...]
Sent: 02 January 2003 23:07
To: aspx_beginners
Subject: [aspx_beginners] Newbie - Connecting to Database


Hi,

I'm trying to use ASP.NET for the first time to connect to a database. 
It's an Access database at c:\database.mdb. I'm using the following code 
in my Web Form:

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script runat="server">

    Sub Page_Load()
    Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
    strConnString += "Data Source=c:\database.mdb"
    data_src.text = strConnString
    
    Dim objConnectionObject As New OledbConnection(strConnString)
    
    try
    objConnectionObject.Open()
    objConnectionObject.Close()
    catch e as exception
    
    con_open.text = "Connection failed to open"
    con_close.text =e.ToString()
    End try
    
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:Label id="data_src" runat="server">Label</asp:Label>
            <asp:Label id="con_open" runat="server">Label</asp:Label>
            <asp:Label id="con_close" runat="server">Label</asp:Label>
        </p>
    </form>
</body>
</html>


Which produces the following results:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb 


Connection failed to open 


System.Data.OleDb.OleDbException: Could not find file 'c:\database.mdb'. 
at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at 
System.Data.OleDb.OleDbConnection.InitializeProvider() at 
System.Data.OleDb.OleDbConnection.Open() at ASP.database_aspx.Page_Load() 


Now, I understand what it is saying - that's pretty obvious. What I'm 
wondering is if anyone can give me any idea why it might not be finding 
the file. I started with it in a folder on the HDD, and moved it to the 
root to be sure it wasn't just my typing! Anyone got any ideas for a 
newbie? Many thanks.

H


*******

This message and any attachment are confidential and may be privileged or otherwise protected from disclosure.  If you are not the
intended recipient, please telephone or email the sender and delete this message and any attachment from your system.  If you are
not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.

For further information about Clifford Chance please see our website at http://www.cliffordchance.com or refer to any Clifford
Chance office.

Message #5 by "Alex Smotritsky" <alex.smotritsky@v...> on Fri, 3 Jan 2003 06:43:18 -0500
Actually, a db table.


-----Original Message-----
From: Alex Smotritsky [mailto:alex.smotritsky@v...] 
Sent: Thursday, January 02, 2003 6:00 PM
To: aspx_beginners
Subject: [aspx_beginners] RE: Newbie - Connecting to Database


In vs.net you can just drag the db from the server explorer on to the
web form and a connection object will be generated for you.


-----Original Message-----
From: Haydn Williams [mailto:haydnw@y...] 
Sent: Thursday, January 02, 2003 11:07 PM
To: aspx_beginners
Subject: [aspx_beginners] Newbie - Connecting to Database


Hi,

I'm trying to use ASP.NET for the first time to connect to a database. 
It's an Access database at c:\database.mdb. I'm using the following code

in my Web Form:

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script runat="server">

    Sub Page_Load()
    Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
    strConnString += "Data Source=c:\database.mdb"
    data_src.text = strConnString
    
    Dim objConnectionObject As New OledbConnection(strConnString)
    
    try
    objConnectionObject.Open()
    objConnectionObject.Close()
    catch e as exception
    
    con_open.text = "Connection failed to open"
    con_close.text =e.ToString()
    End try
    
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:Label id="data_src" runat="server">Label</asp:Label>
            <asp:Label id="con_open" runat="server">Label</asp:Label>
            <asp:Label id="con_close" runat="server">Label</asp:Label>
        </p>
    </form>
</body>
</html>


Which produces the following results:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb 


Connection failed to open 


System.Data.OleDb.OleDbException: Could not find file 'c:\database.mdb'.

at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at 
System.Data.OleDb.OleDbConnection.InitializeProvider() at 
System.Data.OleDb.OleDbConnection.Open() at
ASP.database_aspx.Page_Load() 


Now, I understand what it is saying - that's pretty obvious. What I'm 
wondering is if anyone can give me any idea why it might not be finding 
the file. I started with it in a folder on the HDD, and moved it to the 
root to be sure it wasn't just my typing! Anyone got any ideas for a 
newbie? Many thanks.

H



Message #6 by "Jerry Lanphear" <jerrylan@q...> on Fri, 3 Jan 2003 08:59:11 -0700
Remember that ASP.NET (Or ASP or HTML for that matter) lives and breaths
under Inetpub\wwwroot. I believe your problem is that your file needs to be
in a directory under your project, or you need to create a directory
somewhere else  on your hard drive and declare it as a Virtual directory
under your project.

Regards
----- Original Message -----
From: <Colin.Montgomery@C...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Friday, January 03, 2003 3:34 AM
Subject: [aspx_beginners] RE: Newbie - Connecting to Database


> I have a feeling that you can't name a database "database.mdb".  Try
> changing it's name (and therefore the connection string) and see if it
> helps.
>
> Surely the database must have a purpose, such as customer orders or
> something?  Why not call it something more meaningful.
>
> HTH,
> Col
>
> -----Original Message-----
> From: Haydn Williams [mailto:haydnw@y...]
> Sent: 02 January 2003 23:07
> To: aspx_beginners
> Subject: [aspx_beginners] Newbie - Connecting to Database
>
>
> Hi,
>
> I'm trying to use ASP.NET for the first time to connect to a database.
> It's an Access database at c:\database.mdb. I'm using the following code
> in my Web Form:
>
> <%@ Page Language="VB" %>
> <%@ import Namespace="System.Data" %>
> <%@ import Namespace="System.Data.Oledb" %>
> <script runat="server">
>
>     Sub Page_Load()
>     Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
>     strConnString += "Data Source=c:\database.mdb"
>     data_src.text = strConnString
>
>     Dim objConnectionObject As New OledbConnection(strConnString)
>
>     try
>     objConnectionObject.Open()
>     objConnectionObject.Close()
>     catch e as exception
>
>     con_open.text = "Connection failed to open"
>     con_close.text =e.ToString()
>     End try
>
>     End Sub
>
> </script>
> <html>
> <head>
> </head>
> <body>
>     <form runat="server">
>         <p>
>             <asp:Label id="data_src" runat="server">Label</asp:Label>
>             <asp:Label id="con_open" runat="server">Label</asp:Label>
>             <asp:Label id="con_close" runat="server">Label</asp:Label>
>         </p>
>     </form>
> </body>
> </html>
>
>
> Which produces the following results:
>
> Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb
>
>
> Connection failed to open
>
>
> System.Data.OleDb.OleDbException: Could not find file 'c:\database.mdb'.
> at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at
> System.Data.OleDb.OleDbConnection.InitializeProvider() at
> System.Data.OleDb.OleDbConnection.Open() at ASP.database_aspx.Page_Load()
>
>
> Now, I understand what it is saying - that's pretty obvious. What I'm
> wondering is if anyone can give me any idea why it might not be finding
> the file. I started with it in a folder on the HDD, and moved it to the
> root to be sure it wasn't just my typing! Anyone got any ideas for a
> newbie? Many thanks.
>
> H
>
>
> *******
>
> This message and any attachment are confidential and may be privileged or
otherwise protected from disclosure.  If you are not the intended recipient,
please telephone or email the sender and delete this message and any
attachment from your system.  If you are not the intended recipient you must
not copy this message or attachment or disclose the contents to any other
person.
>
> For further information about Clifford Chance please see our website at
http://www.cliffordchance.com or refer to any Clifford Chance office.
>
>
>
>

Message #7 by "Paul Birch" <paulbirch@b...> on Fri, 3 Jan 2003 16:07:39 -0000
I've seen the error appear if you don't give rights for the asp account to
be able to produce the ldb file that gets generated in the same directory as
the mdb file (the locking file that access uses to manage connections).  Try
giving admin rights to the asp user account that your pages are run as (but
obviously don't leave it like that! security and all...)

-----Original Message-----
From: Jerry Lanphear [mailto:jerrylan@q...]
Sent: 03 January 2003 15:59
To: aspx_beginners
Subject: [aspx_beginners] RE: Newbie - Connecting to Database


Remember that ASP.NET (Or ASP or HTML for that matter) lives and breaths
under Inetpub\wwwroot. I believe your problem is that your file needs to be
in a directory under your project, or you need to create a directory
somewhere else  on your hard drive and declare it as a Virtual directory
under your project.

Regards
----- Original Message -----
From: <Colin.Montgomery@C...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Friday, January 03, 2003 3:34 AM
Subject: [aspx_beginners] RE: Newbie - Connecting to Database


> I have a feeling that you can't name a database "database.mdb".  Try
> changing it's name (and therefore the connection string) and see if it
> helps.
>
> Surely the database must have a purpose, such as customer orders or
> something?  Why not call it something more meaningful.
>
> HTH,
> Col
>
> -----Original Message-----
> From: Haydn Williams [mailto:haydnw@y...]
> Sent: 02 January 2003 23:07
> To: aspx_beginners
> Subject: [aspx_beginners] Newbie - Connecting to Database
>
>
> Hi,
>
> I'm trying to use ASP.NET for the first time to connect to a database.
> It's an Access database at c:\database.mdb. I'm using the following code
> in my Web Form:
>
> <%@ Page Language="VB" %>
> <%@ import Namespace="System.Data" %>
> <%@ import Namespace="System.Data.Oledb" %>
> <script runat="server">
>
>     Sub Page_Load()
>     Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
>     strConnString += "Data Source=c:\database.mdb"
>     data_src.text = strConnString
>
>     Dim objConnectionObject As New OledbConnection(strConnString)
>
>     try
>     objConnectionObject.Open()
>     objConnectionObject.Close()
>     catch e as exception
>
>     con_open.text = "Connection failed to open"
>     con_close.text =e.ToString()
>     End try
>
>     End Sub
>
> </script>
> <html>
> <head>
> </head>
> <body>
>     <form runat="server">
>         <p>
>             <asp:Label id="data_src" runat="server">Label</asp:Label>
>             <asp:Label id="con_open" runat="server">Label</asp:Label>
>             <asp:Label id="con_close" runat="server">Label</asp:Label>
>         </p>
>     </form>
> </body>
> </html>
>
>
> Which produces the following results:
>
> Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb
>
>
> Connection failed to open
>
>
> System.Data.OleDb.OleDbException: Could not find file 'c:\database.mdb'.
> at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at
> System.Data.OleDb.OleDbConnection.InitializeProvider() at
> System.Data.OleDb.OleDbConnection.Open() at ASP.database_aspx.Page_Load()
>
>
> Now, I understand what it is saying - that's pretty obvious. What I'm
> wondering is if anyone can give me any idea why it might not be finding
> the file. I started with it in a folder on the HDD, and moved it to the
> root to be sure it wasn't just my typing! Anyone got any ideas for a
> newbie? Many thanks.
>
> H
>
>
> *******
>
> This message and any attachment are confidential and may be privileged or
otherwise protected from disclosure.  If you are not the intended recipient,
please telephone or email the sender and delete this message and any
attachment from your system.  If you are not the intended recipient you must
not copy this message or attachment or disclose the contents to any other
person.
>
> For further information about Clifford Chance please see our website at
http://www.cliffordchance.com or refer to any Clifford Chance office.
>
>
>
>



Message #8 by "Jerry Lanphear" <jerrylan@q...> on Fri, 3 Jan 2003 09:29:55 -0700
Right,
And, it is unlikely that the ASPNET user has access to the C:\ directory by
default. I hope not. That is why, since we are not talking about an SQL
server here, that the file be placed somewhere within the webservice. Or in
a virtual directory with all proper rights assigned.

Heres a link to a section of msdn which discusses this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csvr2002/ht
m/cs_sp_nettutorial_hgwu.asp

----- Original Message -----
From: "Paul Birch" <paulbirch@b...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Friday, January 03, 2003 9:07 AM
Subject: [aspx_beginners] RE: Newbie - Connecting to Database


> I've seen the error appear if you don't give rights for the asp account to
> be able to produce the ldb file that gets generated in the same directory
as
> the mdb file (the locking file that access uses to manage connections).
Try
> giving admin rights to the asp user account that your pages are run as
(but
> obviously don't leave it like that! security and all...)
>
> -----Original Message-----
> From: Jerry Lanphear [mailto:jerrylan@q...]
> Sent: 03 January 2003 15:59
> To: aspx_beginners
> Subject: [aspx_beginners] RE: Newbie - Connecting to Database
>
>
> Remember that ASP.NET (Or ASP or HTML for that matter) lives and breaths
> under Inetpub\wwwroot. I believe your problem is that your file needs to
be
> in a directory under your project, or you need to create a directory
> somewhere else  on your hard drive and declare it as a Virtual directory
> under your project.
>
> Regards
> ----- Original Message -----
> From: <Colin.Montgomery@C...>
> To: "aspx_beginners" <aspx_beginners@p...>
> Sent: Friday, January 03, 2003 3:34 AM
> Subject: [aspx_beginners] RE: Newbie - Connecting to Database
>
>
> > I have a feeling that you can't name a database "database.mdb".  Try
> > changing it's name (and therefore the connection string) and see if it
> > helps.
> >
> > Surely the database must have a purpose, such as customer orders or
> > something?  Why not call it something more meaningful.
> >
> > HTH,
> > Col
> >
> > -----Original Message-----
> > From: Haydn Williams [mailto:haydnw@y...]
> > Sent: 02 January 2003 23:07
> > To: aspx_beginners
> > Subject: [aspx_beginners] Newbie - Connecting to Database
> >
> >
> > Hi,
> >
> > I'm trying to use ASP.NET for the first time to connect to a database.
> > It's an Access database at c:\database.mdb. I'm using the following code
> > in my Web Form:
> >
> > <%@ Page Language="VB" %>
> > <%@ import Namespace="System.Data" %>
> > <%@ import Namespace="System.Data.Oledb" %>
> > <script runat="server">
> >
> >     Sub Page_Load()
> >     Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
> >     strConnString += "Data Source=c:\database.mdb"
> >     data_src.text = strConnString
> >
> >     Dim objConnectionObject As New OledbConnection(strConnString)
> >
> >     try
> >     objConnectionObject.Open()
> >     objConnectionObject.Close()
> >     catch e as exception
> >
> >     con_open.text = "Connection failed to open"
> >     con_close.text =e.ToString()
> >     End try
> >
> >     End Sub
> >
> > </script>
> > <html>
> > <head>
> > </head>
> > <body>
> >     <form runat="server">
> >         <p>
> >             <asp:Label id="data_src" runat="server">Label</asp:Label>
> >             <asp:Label id="con_open" runat="server">Label</asp:Label>
> >             <asp:Label id="con_close" runat="server">Label</asp:Label>
> >         </p>
> >     </form>
> > </body>
> > </html>
> >
> >
> > Which produces the following results:
> >
> > Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb
> >
> >
> > Connection failed to open
> >
> >
> > System.Data.OleDb.OleDbException: Could not find file 'c:\database.mdb'.
> > at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at
> > System.Data.OleDb.OleDbConnection.InitializeProvider() at
> > System.Data.OleDb.OleDbConnection.Open() at
ASP.database_aspx.Page_Load()
> >
> >
> > Now, I understand what it is saying - that's pretty obvious. What I'm
> > wondering is if anyone can give me any idea why it might not be finding
> > the file. I started with it in a folder on the HDD, and moved it to the
> > root to be sure it wasn't just my typing! Anyone got any ideas for a
> > newbie? Many thanks.
> >
> > H
> >
> >
> > *******
> >
> > This message and any attachment are confidential and may be privileged
or
> otherwise protected from disclosure.  If you are not the intended
recipient,
> please telephone or email the sender and delete this message and any
> attachment from your system.  If you are not the intended recipient you
must
> not copy this message or attachment or disclose the contents to any other
> person.
> >
> > For further information about Clifford Chance please see our website at
> http://www.cliffordchance.com or refer to any Clifford Chance office.
> >
> >
> >
> >
>
>
>
>
>
>


  Return to Index