none
No physical update in MSSQL after C# INSERT query RRS feed

  • Question

  • Hello.

    There are no problems in Executing this query, after that I can query about the added data in the application and it works - the data is stored in the database, but it looks like it's stored in the memory - not in the physicall database. I know there is a solution, but I just can't find it... Please help

    Code Block

    Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Baza.mdf";Integrated Security=True;User Instance=True



    Code Block

              SqlConnection connection = null;
                try
                {
                    string queryString = "INSERT INTO [User] (Login, Pass) VALUES ('" + userLogin + "', '" + userPass + "')";

                    connection = new SqlConnection(Settings.Default["BazaConnectionString"].ToString());
                    SqlCommand command = new SqlCommand(queryString, connection);
                    connection.Open();

                    int wynik = command.ExecuteNonQuery();
                    bool wynik = true;
                    if (reader.HasRows)
                        wynik = true;
                    else
                        wynik = false;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Close();
                    }
                }



    There are no problems in Executing this query, after that I can query about the added data in the application and it works - the data is stored in the database, but it looks like it's stored in the memory, not in the physicall database. I know there should be a solution, but I just can't find it... Please help
    Tuesday, November 27, 2007 8:37 AM

Answers

  • The first thing to check is to see if Visual Studio is overwriting your database every time you do a build.  Does the database get updated if you run the .exe directly (rather than from inside VS)?  If so, VS is the culprit.  Check out the FAQ in the very first topic in this forum.

    Thursday, November 29, 2007 7:55 PM