locked
Error adding connection in Server Explorer: “Unable to add data connection. ExecuteScalar requires an open and available connection.” RRS feed

  • Question

  • User1909955381 posted

    I'm using Visual Studio 2008, and my database is SQL Server 2000.

    I want to add a connection to the Server Explorer in VS. The Data source is Microsoft SQL Server (SqlClient). After entering in all my information and I click Test Connection, it is successful.

    But when I click OK, I get the error:

    Unable to add data connection. ExecuteScalar requires an open and available connection. The connection's current state is closed.

    What's going on here?

    Monday, September 13, 2010 3:01 PM

Answers

  • User1384885075 posted

    Hi,  found this forum as I was having the same problem.  Another forum suggested restarting Visual Studio and adding the connection again... lo and behold, it worked!  The only thing I did differently was I didn't test the connection the second time.

    Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 18, 2012 11:55 PM

All replies

  • User2060565753 posted

    can i get to see ur code??

    it will be helpful to resolve ur issue 

    Tuesday, September 14, 2010 3:25 AM
  • User-314351324 posted

    I am getting the same exact message. It doesn't make sense that the test connection works ok.  

    I had been able to connect to this SQL Server when developing on another machine.

    I am wondering if it has something to do with the network protcols or setup?

    If you have found a solution to this problem please email me, it would be very much appreciated.

     

    Thanks

    deedee1969

    Wednesday, September 15, 2010 4:22 PM
  • User-1453258508 posted

    Did you open the connection before calling executescalar?

    Sounds like you created the SqlConnection object but did not call the open method.

    Wednesday, October 13, 2010 12:26 PM
  • User1384885075 posted

    Hi,  found this forum as I was having the same problem.  Another forum suggested restarting Visual Studio and adding the connection again... lo and behold, it worked!  The only thing I did differently was I didn't test the connection the second time.

    Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 18, 2012 11:55 PM
  • User71929859 posted

    Hi,

    Can we see the part of your coding where you do the SQL connection part? Check whether you are closing the connection before you reach to the ExecuteScalar method. Or may be, you are never opening a connection. It's a problem with your code. Not a problem with your network connection, Visual Studio or SQL server, I guess.

    Thursday, January 19, 2012 7:58 AM
  • User-175565078 posted

    Thanks Bonjufra..

    That was it.. I just had to restart Visual Studio and it worked  !

    Thursday, April 4, 2013 10:39 AM