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 6926461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:55:16+00:00 2026-05-27T10:55:16+00:00

I am developing a web app and have encountered a problem. I need to

  • 0

I am developing a web app and have encountered a problem. I need to insert username and ip address into a SQL database table “log” when someone tries (successfully or unsuccessfully) to login. ID, time and date are inserted automatically…
For some reason I am unable to get it working in my login form. INSERT statement works ok if I initiate it from another form, but I can’t get it working together with the SELECT statement I use for checking login credentials.

I have tried different solutions, but none of them inserts data into the table… It does not throw an error, it just doesn’t insert a new row into “log” table.

Any help is appreciated. 🙂

protected void btnLog_Click(object sender, EventArgs e)
{
    using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ToString()))
    {
        string username = null;
        string password = null;
        string ipAddress = null;

        SymCryptography cryptic = new SymCryptography();
        SqlCommand cmdSelect = new SqlCommand();
        SqlCommand cmdLog = new SqlCommand();
        SqlDataReader myReader = null;

        cmdSelect.Connection = conn;
        cmdLog.Connection = conn;

        cmdSelect.CommandText = "SELECT * FROM uporabniki WHERE up_ime=@up_ime AND geslo=@geslo";
        cmdSelect.CommandType = CommandType.Text;
        cmdLog.CommandText = "INSERT INTO log (up_ime, ip) VALUES (@up_ime, @ip)";
        cmdLog.CommandType = CommandType.Text;

        cmdSelect.Parameters.Add("@up_ime", SqlDbType.NVarChar, 20).Value = tbUsr.Text;
        cmdSelect.Parameters.Add("@geslo", SqlDbType.NVarChar, 20).Value = cryptic.Encrypt(tbPwd.Text);
        cmdLog.Parameters.Add("@up_ime", SqlDbType.NVarChar, 20).Value = tbUsr.Text;
        cmdLog.Parameters.Add("@ip", SqlDbType.NVarChar, 20).Value = ipAddress;

        conn.Open();
        try
        {
            //cmdLog.ExecuteNonQuery();  I tried it here, but it doesn't work
            myReader = cmdSelect.ExecuteReader();
            if (myReader.Read())
            {
                username = myReader["up_ime"].ToString();
                password = myReader["geslo"].ToString();
                Session["rights"] = myReader["pravice"];
                Session["login"] = "OK";
                pravice = true;
            }
            myReader.Close();
            //cmdLog.ExecuteNonQuery();  I tried it here, but it doesn't work
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        conn.Close();
    }
    //I tried to open connection again, but stil INSERT does not work
    /* using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ToString()))
    {
        string ipAddress = null;
        SqlCommand cmdLog = new SqlCommand();
        cmdLog.Connection = conn;
        cmdLog.CommandText = "INSERT INTO log (up_ime, ip) VALUES (@up_ime, @ip)";
        cmdLog.CommandType = CommandType.Text;
        cmdLog.Parameters.Add("@up_ime", SqlDbType.NVarChar, 20).Value = tbUsr.Text;
        cmdLog.Parameters.Add("@ip", SqlDbType.NVarChar, 20).Value = ipAddress;
        conn.Open();
        try
        {
            cmdLog.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        conn.Close();
    }

    if (pravice == true)
    {
        Response.Redirect("Default.aspx");
    }
    else
    {
        Response.Redirect("Login.aspx");
    }*/ 
}
  • 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-05-27T10:55:17+00:00Added an answer on May 27, 2026 at 10:55 am

    Your not executing your cmdLog.ExecuteNonQuery(); statement.

    Also, try opening a query window in your sql database and run the following against it.

    INSERT INTO log (up_ime, ip) VALUES (<some time>, <test ip text>)
    

    If the error lies in sql server you should be returned an error message stating if the problem lies withing SQL Server.

    Also try changing:

        cmdLog.Parameters.Add("@up_ime", SqlDbType.NVarChar, 20).Value = tbUsr.Text;
        cmdLog.Parameters.Add("@ip", SqlDbType.NVarChar, 20).Value = ipAddress;
    

    To:

      cmdLog.Parameters.Add("@up_ime", tbUsr.Text);
      cmdLog.Parameters.Add("@ip",  ipAddress);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a web app that connects to a SQL 2000 database. Everything
I have a strange problem... I am developing a web app to search house
We have been developing a DB web app which constantly queries an SQL store
I'm developing a web app for iOs device, but I have a problem with
I am developing a web app using servlets and jsps. I have a question
So I have been developing a small ASP.NET web app in C# for my
I am developing a web app which requires a username and password to be
I'm developing a web app and currently using sql server 2008 for it. But,
We are developing a web app that will have a pretty complex user and
I'm developing a QA web-app which will have some points to evaluated assigned 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.