3

i am calling the OledbConnection to Microsoft Access Database. there is no issue calling the method and also retrieves necessary data.

i dont know after that method the session timeouts automatically. and goes to login page. why? i have lost entire day debugging and finding the issue.

string strQuery = "select count(LOC1) as LOC1 from shrmwise";
DataTable dt = new DataTable();

using (OleDbConnection connection = new OleDbConnection(connectionString))
{
    connection.Open();

    using (OleDbCommand command = new OleDbCommand(strQuery, connection))
    {
        try
        {
            OleDbDataReader reader = command.ExecuteReader();
            dt.Load(reader);
            reader.Close();
        }
        catch (Exception ex)
        {
            throw ex;
            //Console.WriteLine(ex.Message);
        }
        finally
        {
            connection.Close();
        }
        return dt;
    }
}

Edited

Does not timeout if the above method call is commented.

it does not timeout on localhost, but on live server.

my connectionString as follows

string connectionString =
       @"Provider=Microsoft.Jet.OLEDB.4.0;" +
       @"Data Source=E:\Data\MyDatabase.mdb;" +
       @"User Id=;Password=;";
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Do you have access to the folder _E:\Data\MyDatabase.mdb_ on the server? Remember that you need to give permissions Read/Write on that folder to the user making the connection (IUSR if ASP.NET) otherwise access will never work. And if that folder is outside the root of your site you need a full trust to your IIS site to access that folder. – Steve Sep 27 '17 at 14:16
  • Yes, full permission given to everyone – Kailash Chandra Polai Sep 27 '17 at 14:21
  • 2
    If you move that database inside the APP_DATA folder of your site, do you still have the problem? (Of course change accordingly the conn string) – Steve Sep 27 '17 at 14:23
  • Hi @Steve, Nice find, after moving to APP_DATA, it works, no timeouts. thanks a lot, i have lost 3 days. please answer your post so that i can assign the bounty to you – Kailash Chandra Polai Sep 28 '17 at 07:23

1 Answers1

2

Usually in a IIS/ASP.NET environment the application runs with MEDIUM TRUST settings and not with FULL TRUST. This means that your code cannot access any part of the file system that resides outside the root of your site.

To resolve the problem in which applications need a place where they can read and write without worrying about too much security restrictions a convention has been adopted.
The convention is to have a subfolder of the site root called APP_DATA where the user (IUSR) under which the ASP.NET service runs your application has Read/Write permissions. Here you can place your database or other read/write files. Create subfolder to store different type of documents and so on.

So your problem can be solved just following the convention and moving the database in that folder. Or, after verifying the security consequences of such move, force your site to run in FULL TRUST.

Of course if you have to manually create the APP_DATA folder be sure to also set the correct permissions for the IIS user.

Steve
  • 213,761
  • 22
  • 232
  • 286