I am using the following code to connect to an Microsoft SQl Server database but I always get an error

 var conn = @"Server=(local)\localhost;Database=Training;";
        using (SqlConnection objSqlConnection = new SqlConnection(conn))
        {
            try
            {
                objSqlConnection.Open();
                Console.Write("Connection is successfull");
            }
            catch (System.Data.SqlClient.SqlException sqlException)
            {
               Console.WriteLine(sqlException.Message);
            }
        }

and the error I get is:

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in     System.Data.dll
The thread 'vshost.RunParkingWindow' (0xd28) has exited with code 0 (0x0).
The thread '<No Name>' (0x1550) has exited with code 0 (0x0).
The program '[6440] DataAccess.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

没有正确的解决方案

其他提示

Make sure your System.Data.dll is correctly referenced in your code.

First chance exception messages most often do not mean there is a problem in the code. For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled.

For code without exception handling, the debugger will receive a second chance exception notification and will stop with a unhandled exception.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top