Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2005, 02:56 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default access database connection problem

Hi

i have one DButil.cs class file for database connection
but in .cs file server.mappath() is not work so how can i use my database connection path




shailesh kavathiya
http://www.kavathiya.20m.com
__________________
Shailesh Kavathiya
===============
Good Morning SMS
 
Old June 17th, 2005, 08:44 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When you are out of the context of a ASP.NET page class, you do have direct access to the server/response/request objects that are available off of the Page class.

However, you can access them off of the Current property of the HttpContext class:

System.Web.HttpContext.Current.Server

-Peter
 
Old June 18th, 2005, 10:52 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

Hi Peter

I use System.Web.HttpContext.Current.Server i got successful connection with access


Thanks
Shailesh




shailesh kavathiya
http://www.kavathiya.20m.com
 
Old June 22nd, 2005, 02:44 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

Hi peter

I have one problem
I have developing small appliaction
in that appliaction we have two part 1 admin part and 1 client part means end user part

i have one classes folder and in that class folder have all code file and connetion file
in dbutil.cs file have my database connetion
[code]
strConn="Provider=Microsoft.Jet.OLEDB.4.0;data source="+System.Web.HttpContext.Current.Server.Map Path("../data/data.mdb")+";";
[code]

first i have develop admin modula in admin folder
in admin part is complited succesfully no database connection error

when i have start work on clint site in root folder
at that try to connect with my database using dbutil.cs connection string i cant able to find my data base in root folder

i got error "database path not found" c:\Inetpub\wwwroot\data\data1.mdb"

but my database path is c:\shailesh\data\data.mdb

pls help me


Thanks
Shailesh


shailesh kavathiya
http://www.kavathiya.20m.com
 
Old June 22nd, 2005, 06:08 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I assume from your post that you have some subsolder that contains the admin part of your application.

What's happening here is that the IIS root lives here:
    c:\Inetpub\wwwroot (http://localhost/)

And your application lives here:
    c:\shailesh (http://localhost/shailesh)

while the data file lives here:
    c:\shailesh\data\data.mdb (http://localhost/shailesh/data/data.mdb)

In your admin part the data file is referenced like this:
    http://localhost/shailesh/admin/../data/data.mdb
Which returns
    c:\shailesh\data\data.mdb

But your client part at the application root tries this:
    http://localhost/shailesh/../data/data.mdb
Which is returning
    c:\Inetpub\wwwroot\data\data.mdb

You need to change your location relative virtual path in the call to MapPath to a root relative path so that you can always reference the data file off the application root regardless of where the calls are being made.

To solve this problem for any folder/page location, change the data file path to a root relative virtual path with the ~ character as substitute for your application root. The Server.MapPath method will replace it with the full application root path and make it relative to the SERVER root (i.e. any path that starts with "/"). This will make the reference work from any location in your application.

For example:

strConn= "Provider=Microsoft.Jet.OLEDB.4.0;data source=";
strConn+= System.Web.HttpContext.Current.Server.MapPath("~/data/data.mdb") + ";";

-Peter
 
Old June 22nd, 2005, 09:45 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

hi peter

Thank you very much

your answer too much useful for me and you have expain in esay understable language it help full for me to understand

Agin Thanks


shailesh



shailesh kavathiya
http://www.kavathiya.20m.com
 
Old July 5th, 2005, 03:30 AM
Authorized User
 
Join Date: May 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to shaileshk Send a message via Yahoo to shaileshk
Default

Hi

i user this method ("~/data/data.mdb") it working fine in my pc but when i upload this application on my website it not working pls check

why i got that error on web site

Please help me

Thanks
Shailesh


shailesh kavathiya
http://www.kavathiya.20m.com

Last edited by shaileshk; November 4th, 2011 at 04:26 PM.. Reason: deleted link





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection DataGrid to Access database Rado C# 1 April 25th, 2005 04:59 AM
ms access database connection android66 Javascript 1 December 1st, 2004 07:19 AM
Access Database connection widad Classic ASP Databases 3 November 5th, 2004 05:24 AM
Connection to a Access database aadz5 ASP.NET 1.0 and 1.1 Basics 2 October 13th, 2003 06:35 AM
Access Database Connection Problems jdmeier Classic ASP Databases 1 August 13th, 2003 10:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.