0
Reply

(~) or (..) not pointing to virtual path/root , instead it's pointing to system path/root for oledbdataconnection C# asp.net

Jones Jay

Jones Jay

Dec 2 2008 11:08 AM
2.6k

I'm designing a website which works great on my local machine with full path in the connection string as mentioned below

private static string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" +

" C:\\myweb\\Projects\\App_Data\\ASPNetDB.mdb";

private static OleDbConnection oledbconn = new OleDbConnection(connectionString);

(1)  now i need to host this site on 3rd party server  where i need to write virtual path of  .mdb file , so i tried using (~) as mentioned below

private static string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + " ~\\App_Data\\ASPNetDB.mdb";

private static OleDbConnection oledbconn = new OleDbConnection(connectionString);

 

which gives me an error

'C:\WINDOWS\system32\~\App_Data\ASPNetDB.mdb' is not a valid path.

 

(2)  Then i tried replacing (~) with (..) like mentioned below

private static string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + " ..\\App_Data\\ASPNetDB.mdb";

private static OleDbConnection oledbconn = new OleDbConnection(connectionString);

which gives me an error

'C:\WINDOWS\App_Data\ASPNetDB.mdb' is not a valid path.

(3) on the same page if i use AccessDataSource  with below mentioned (Starting with  .. or  ~) for .mdb it resolves virtual path and works great on the 3rd party server as well

private static AccessDataSource myconn = new AccessDataSource("..\\App_Data\\ASPNetDB.mdb", " Select * from tbltest");

 

 

I do not know why but it's not poinging  the virtual directory with oledbdataconnection & it is  pointing to my system root i.e c:\windows.... 

any help will be appreciated a lot ,,,

i'm writing this code in the code (.cs) file in app_code directory

with below mentioned references

using System;

using System.Data;

using System.Data.OleDb;

using System.Configuration;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;