简体   繁体   中英

SQL Insert query working all week now it won't work at all

What does

---------------------------

---------------------------
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.)
---------------------------
OK   
---------------------------

that actually mean?

I take that to mean, "Things took too long so I just gave up."

I don't understand why there was a timeout though, because I set the timeout to 4 minutes and this error popped up in less than 30 seconds.

Why has this exact code been working the past week and now it just fails every single time???

I tried setting cmd.CommandTimeout = 240 which is a pretty long time to wait when debugging, and same problem. Nothing is getting updated in the database anymore. I don't understand what has changed.

    try
    {
        // Insert into database
        sqlconnection = new SqlConnection(@"Data Source=s1-removed-om;Initial Catalog=D-removed-t;Persist Security Info=True;User ID=D-removed-;Password=97-removed3-45;");

        sqlconnection.Open();

        cmd = new SqlCommand();
        cmd.Connection = sqlconnection;

        int count = 0;

        foreach (var item in files)
        {
            cmd.CommandText = @"insert into Images (Name, Credits) values ('" + item.Value + "', '" + credits + "')";
            cmd.ExecuteNonQuery();

            count++;
        }

        doneUpdatingDB = true;
    }
    catch (Exception exception)
    {
        MessageBox.Show(exception.Message);
        doneUpdatingDB = false;
    }

It's not a command timeout, you're experiencing a connection timeout here. It means that your client couldn't authenticate to the SQL Server in time (time being 30 sec by default). Increase the connection timeout. If this doesn't help, restart local machine. If this doesn't help, notify the server's administrator about the issue.

What framework are you using?

Try this:

1. Restart Visual Studio.
2. Re-build project. 
3. Re-install latest .NET Framework. 

Check this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM