System.Threading.ThreadAbortException oConn.Open C# MS SQL

QuinnDester
QuinnDester used Ask the Experts™
on
I keep get this error System.Threading.ThreadAbortException  when the line oConn.Open executes, and the class below stops.

i have stepped through the code, var's are being passed through correctly and the conection string is being picked up correctly.

i have connected to the database using the VS database explorer to verify that VS can connect to the database, but i cant track down the cause of this problem, could someone please help me with this, thank you
public static bool newAcc(string thisUser, string thisEmail, string thisUserID)
    {
        try
        {
            using (SqlConnection oConn = new SqlConnection(connectionString))
            {
                oConn.Open();
                using (SqlCommand oComm = oConn.CreateCommand())
                {


                  
                    

                    oComm.Parameters.Clear();
                    oComm.CommandType = CommandType.StoredProcedure;
                    oComm.Parameters.AddWithValue("@thisUser", thisUser);
                    oComm.Parameters.AddWithValue("@thisEmail", thisEmail);
                    oComm.Parameters.AddWithValue("@thisUserID", thisUserID);
                    oComm.Parameters.AddWithValue("@datetime", DateTime.Now.ToUniversalTime());

                    oComm.CommandText = "newUser";
                    oComm.ExecuteNonQuery();
                }

            }
            return true;
        }
        catch { return false; }
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Please check that your Visual Studio debug exceptions are not checked.
The CLR might throw this exception if a Thread.Abort is called.

If you have it configured to stop on any exception then remove the checks and try again.
You might also try to run the Exe and see if it crashes.

You can read more about it here:
http://blogs.msdn.com/b/clrteam/archive/2009/04/28/threadabortexception.aspx
and here:
http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/5507f7d6-627e-4449-9df1-b582f11cf483

I hope it helps

Author

Commented:
No just checked and its not checked.

What do you mean by run the EXE?

Commented:
Compile it and run the compiled exe, see if the exception causes it to crash (As you describe it, it will probably happen).

11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Author

Commented:
its a web site, there isnt an exe

Author

Commented:
it doesnt crash, it just skips the conection to the database then continuse on, but doesnt dispaly the data it was supposed to pick up
Top Expert 2012
Commented:
You have not posted the actual message so I am going to have guess that you have not setup the permissions correctly on the website.  In other words anonymous users do not have access as you connection is using Windows Authentication.

If you want a more meaningful response, then you are going to have to elaborate.  Error message, connections string, etc.
Please specify the Connection String that you are using. I think something is missing in ConnectionString's attributes. Let me first examine that.
A possible solution I can give you is this code :
public static bool newAcc(string thisUser, string thisEmail, string thisUserID)
    {
        try
        {
            using (SqlConnection oConn = new SqlConnection(connectionString))
            {
		Thread.Sleep(1000);
		Thread.CurrentThread.Join(1000);
                oConn.Open();
                using (SqlCommand oComm = oConn.CreateCommand())
                {
                    oComm.Parameters.Clear();
                    oComm.CommandType = CommandType.StoredProcedure;
                    oComm.Parameters.AddWithValue("@thisUser", thisUser);
                    oComm.Parameters.AddWithValue("@thisEmail", thisEmail);
                    oComm.Parameters.AddWithValue("@thisUserID", thisUserID);
                    oComm.Parameters.AddWithValue("@datetime", DateTime.Now.ToUniversalTime());

                    oComm.CommandText = "newUser";
                    oComm.ExecuteNonQuery();
                }
            }
            return true;
        }
        catch { return false; }
    }

Open in new window


Don`t forget to add a using statement to System.Threading Namespace.
Please post the inner exception and caller stack data here.. Again you should always examine the exception in details its a best practice..
One more question does it occur for this code block or everywhere in your class when you are trying to Open the connection??

Author

Commented:
Thank you, double checked and realised i had spelt the database name wrong

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial