简体   繁体   English

在不创建数据库的情况下测试SQL Server连接

[英]Test SQL Server Connection without creating database

I am using Entity Framework code-first approach. 我正在使用Entity Framework代码优先方法。 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. 我想开发一种形式,用户可以在其中输入SQL Server详细信息,例如服务器名称,用户ID,密码和数据库名称,这些信息将首先由代码创建。

But before creating a database I want to test the connection to SQL Server without creating any test database. 但是在创建数据库之前,我想在不创建任何测试数据库的情况下测试与SQL Server的连接。 Is it possible to test SQL Server connection without creating any database? 是否可以在不创建任何数据库的情况下测试SQL Server连接?

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. 请提供任何无需数据库即可测试SQL Server连接的逻辑。

Look for an open listener on port 1433 (the default port). 在端口1433(默认端口)上查找打开的侦听器。 If you get any response after creating a tcp connection there, the server's probably up.- 如果在该处创建tcp连接后收到任何响应,则服务器可能已启动。-

         try
        {
            TcpClient client = new TcpClient();
            client.Connect("Your Host", 1433);
            Console.WriteLine("Connection open");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Connection not open");
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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