Hi to every one ..

I have Access database Access 2007 . and i need to connect with ASp.net ..nad i put database in db folder but it gives errors ...

if provide Database1.accdb in connection string (following error)

Unrecognized database format 'C:\Documents and Settings\erum.mirza\My Documents\Visual Studio 2008\Projects\ajax\ajax\db\Database1.accdb'.

if provide Database1. mdb in connection string (following error)

Could not find file 'C:\Documents and Settings\erum.mirza\My Documents\Visual Studio 2008\Projects\ajax\ajax\db\Database1.mdb'.

and here is the piece of code

protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                string ConnectString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("App_Data\\Database1.accdb; Persist Security Info=False;"); 
                OleDbConnection objCon; 
                OleDbCommand objCmd; 
                DataSet Ds = new DataSet(); 

                string GetSql = string.Empty; 
                GetSql = "(SELECT * FROM Table1)"; 
                using (objCon = new OleDbConnection(ConnectString)) 
                { 
                    using (objCmd = new OleDbCommand(GetSql, objCon)) 
                    { 
                        OleDbDataAdapter Da = new OleDbDataAdapter(objCmd); 
                        Da.Fill(Ds); 
                    } 
                } 



            } 
        }

ASP.NET is problably running on a IIS server. You have to put it in the root folder of your IIS server.

Having said that...............

same issue ..

Member Avatar for stbuchok

You realize that you are pointing to App_Data in your connection string. Yet in neither of the 2 errors are you putting it in the App_Data folder. Also, this is completely wrong:

Server.MapPath("App_Data\\Database1.accdb; Persist Security Info=False;")

try this instead:

Server.MapPath("App_Data\\Database1.accdb") + "; Persist Security Info=False;"

Also, whatever Server.MapPath("") + "App_Data" comes to, that is where you need to put the file.

Also, this is the javascript part of the forum. You will be better served to ask this in the ASP.Net part of the forum. I suggest moving it there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.