0

I am using Entity Framework code-first approach. I want to develop a form in which user will enter SQL Server detail like server name, user ID, password and database name which will be created by code first.

But before creating a database I want to test the connection to SQL Server without creating any test database. Is it possible to test SQL Server connection without creating any database?

I tried creating a test database in that server and verify but this method is quite not acceptable as creating a test database and then delete it is not the solution to the issue.

Please provide any logic that can test SQL Server connection without database.

2
  • check my edited answer. Commented Aug 26, 2015 at 7:40
  • You can check connectivity to master database. Commented Aug 26, 2015 at 7:43

1 Answer 1

1

Look for an open listener on port 1433 (the default port). If you get any response after creating a tcp connection there, the server's probably up.-

         try
        {
            TcpClient client = new TcpClient();
            client.Connect("Your Host", 1433);
            Console.WriteLine("Connection open");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Connection not open");
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Can you provide any sample code or url that can help me out?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.