0

I have a hosted website, and I need to add a database with password and log-in information. (MS Access DB), I tried a lot but can't connect with it (on local machine it works). I tried to change connection string but it still doesn't work. Database is in folder App_Data. Here's what I type in Login.aspx page:

OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
   + Server.MapPath("~\\App_Data\\WebSiteDatabase.accdb");
con.Open();

This does not work. What do I need to change? I've put my web site on somee.com

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
user2362291
  • 17
  • 2
  • 3
  • 7

1 Answers1

3

Did you check the help page on SOMEE for connecting to an access database?

QUOTE FROM Somee.com help:

Connect to MS access database usin DSN-less connection
Doka only provides DSN-less connection to the Access databases, because they are much faster and there is no possible names conflict. Most of the problems are in choosing right connection string. Here is an example of tested connection string to MS Access database:
We suppose that your database resides in “Database” subfolder and it name is “TestDB.mdb”.
You’ll have to use Server.MapPath(“Database\TestDB.mdb”) in order to get physical location of database.

So connection string would be:

"PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("Database\TestDB.mdb") 

And the way to utilize it:

OleDbConnection conn = null;
OleDbDataReader reader = null;
try
{
    conn = new OleDbConnection(
        "Provider=Microsoft.Jet.OLEDB.4.0; " + 
        "Data Source=" + Server.MapPath("Database/TestDB.mdb"));
    conn.Open();

    OleDbCommand cmd = 
        new OleDbCommand("Select * FROM Table1", conn);
    reader = cmd.ExecuteReader();

    datagrid.DataSource = reader;
    datagrid.DataBind();
}
    //        catch (Exception e)
    //        {
    //            Response.Write(e.Message);
    //            Response.End();
    //        }
finally
{
    if (reader != null)  reader.Close();
    if (conn != null)  conn.Close();
}
Jake1164
  • 12,291
  • 6
  • 47
  • 64
  • I saw this. but everything VS sayes that & can't be used in string and all is read – user2362291 May 14 '13 at 13:20
  • What does that mean? What cant be used in a string? All what is read? – Jake1164 May 14 '13 at 13:23
  • I tried to change con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~\\App_Data\\WebSiteDatabase.accdb"); to "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("App_Data\WebSiteDatabase.accdb") and it shows errors – user2362291 May 14 '13 at 13:25
  • So you can connect to the database, you don't have write access? – Jake1164 May 14 '13 at 13:25
  • what errors? can you be more specific? – Jake1164 May 14 '13 at 13:28
  • This is the website http://testeducationmagazine.somee.com/ when I try to login it shows error – user2362291 May 14 '13 at 13:29
  • "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("App_Data\WebSiteDatabase.accdb") i have to write in html code ? – user2362291 May 14 '13 at 13:30
  • 1
    Try following a tutorial. http://msdn.microsoft.com/en-us/library/ms971485.aspx and remove the password until you have it working and then add the password once you are sure you can connect. – Jake1164 May 14 '13 at 13:35
  • I read this. Changed the connection string . on local machine it runs good , but still when I put the site on hosting it shows error – user2362291 May 14 '13 at 13:42
  • 1
    **Welcome to the 2k club. Congratulations.** – Undo May 23 '13 at 14:29