确定SQL连接是本地连接还是远程连接 [英] Determine if SQL connection is local or remote

查看:140
本文介绍了确定SQL连接是本地连接还是远程连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个运行sql脚本的应用程序,或者在本地或远程sql服务器上运行,以更新应用程序的值。使用以下方法检查连接状态:



TcpClient客户端=新TcpClient(serverName,1433);



一旦我们知道我们可以使用端口进行监听,我就必须使用Windows / SQL服务器身份验证将登录凭据传递给SQL服务器。但问题是应用程序需要确定它所连接的服务器是本地还是远程,基于该服务器的功能可以变化。

例如:如果使用本地Windows身份验证,请使用集成安全性。



任何人都可以帮助我了解我将如何确定如果连接是远程的或本地的,基于此我的应用程序可以开发以启用不同的功能/属性。



谢谢。

I am trying to develop an application that runs sql scripts either or on a local or on a remote sql server to update values on the application. The connection status is checked using:

TcpClient client = new TcpClient(serverName, 1433);

Once we know that we can listen using the port, I will have to pass the login credentials to the SQL server either using Windows/SQL server authentication. But the problem is that the application needs to determine if the server it is connecting to is local or remote based on which the functionality of the application can vary.
e.g: Use integrated security if using local windows authentication.

Can anyone please assist me in as to how I would be able to determine if the connection is remote or local as based on this my application can be developed to enable different functionality/properties.

Thank you.

推荐答案

你通常不会这样做。在安装时,您会要求安装应用程序的人员提供SQL Server名称和实例,端口号和要使用的凭据,从而为他们提供使用Windows身份验证的选项。然后,您将根据该信息构造连接字符串,并在需要时测试连接。
You wouldn''t normally do this. At install time, you''d ask the person installing the app for the name of the SQL Server and instance, port number, and credentials to use, giving them the option of using Windows Authentication. You''d then construct the connection string from that information and test the connection if required.


这篇关于确定SQL连接是本地连接还是远程连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆