Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:56:09+00:00 2026-06-01T15:56:09+00:00

I have written a code to insert the data to SQL LITE database as

  • 0

I have written a code to insert the data to SQL LITE database as follows

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        count = 0;
       Session["x"] = "session value";

    }
}

protected void Button1_Click(object sender, EventArgs e)
{
    string path = Server.MapPath("bin/sampldb.db");
    SQLiteConnection conn = new SQLiteConnection("Data Source=" + path + "");
    try
    {
        conn.Open();
        SQLiteCommand cmd = new SQLiteCommand();
        cmd.Connection = conn;
        string txt="insert into stu values("+TextBox1.Text  +",'"+TextBox2.Text+"')";
        cmd.CommandType = CommandType.Text;
        cmd.CommandText  = txt;
        cmd.ExecuteNonQuery();
        conn.Close(); 
    }
    catch (Exception ex)
    {
        Label1.Visible = true;
        Label1.Text = "Error:" + ex.Message;
    }

}

After inserting while retrieving data Session is getting null I don’t know why

 protected void Button2_Click(object sender, EventArgs e)
{
    if (Session["x"] != null) // Getting Null here
    {
        Label1.Visible = true;
        Label1.Text = Session["x"].ToString();
        DataSet m_oDataSet = new DataSet();
        string path = Server.MapPath("bin/sampldb.db");
        SQLiteConnection conn = new SQLiteConnection("Data Source=" + path + "");
        try
        {
            conn.Open();
            SQLiteCommand cmd = new SQLiteCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string txt = "select * from stu";
            cmd.CommandText = txt;

            SQLiteDataAdapter adp = new SQLiteDataAdapter();
            adp.SelectCommand = cmd;
            adp.Fill(m_oDataSet);
            GridView1.DataSource = m_oDataSet.Tables[0];
            GridView1.DataBind();

        }
        catch (Exception ex)
        {
            Label1.Visible = true;
            Label1.Text = "Error:" + ex.Message;
        }
        finally
        {
            conn.Close();
        }

    }
}

The same code when tested in Sql server 2008 works fine

protected void BtnSqlInsert_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(cnstr);
    con.Open();
    SqlCommand cmd = new SqlCommand("Insert into [User] values ('" + TextBox1.Text + "','" + TextBox2.Text + "')", con);
    cmd.ExecuteNonQuery();
    con.Close();
}
protected void BtnSqlGet_Click(object sender, EventArgs e)
{
    if (Session["x"] != null) //Able to get session here
    {
        Label1.Visible = true;
        Label1.Text = Session["x"].ToString();
    }
}

My sql lite path is from Bin folder as shown in image

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:56:11+00:00Added an answer on June 1, 2026 at 3:56 pm

    your app writes to DB (which is in BIN folder). That causes app restart => in-proc session gets lost. You should NOT solve the consequence (by using StateServer mode), you should fix the original reason – move db file into another folder, away from BIN folder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written code to insert an Image in SQL server but it throws
I am relatively new to Perl.I have been trying to insert data to database
I have written a piece of code, it copies the data from the entire
Scenario I have a stored procedure written in T-Sql that I use to insert
I have written a working T-SQL MERGE statement. The premise is that Database A
I have written the following code to place the image path into sql server
I have written the code for simple update.I am able to insert and delete
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written code to perform a function that could take a while to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.