连接SQL Server数据库的问题 [英] Problem to connect SQL server database

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

问题描述

嗨;



我有一个连接sql server数据库的C#程序。

我可以在我的计算机上用这个连接字符串连接这个数据库;

数据源= DESKTOP-E0NKE43 \\MYINSTANCE;数据库= MYDB;集成安全性=真;



但是当我把这个程序放到另一台PC上时,我无法连接这个连接字符串。



我的sql server实例对其他计算机是可见的,那么我能做什么呢吗?





谢谢。



PS:我的电脑尝试连接是在sql server上的同一网络中。

P.S1:我还没有尝试在sql server上创建一个新的登录用户,因为我认为Windows身份验证适用于本地计算机。



我尝试过:



我启用了sql server以允许传入的请求。而且我非常确定从其他计算机可以看到sql server实例,因为我的程序会检查并列出所有可用的sql server实例。我也检查了使用PowerShell。

我尝试用我的计算机名,我的IP地址等更改我的连接字符串数据源。

解决方案

集成安全性可能是你的问题,如果数据库仍然在同一台PC上 - 新机器上的用户可能无权访问你的电脑。



无论如何,您不应该在生产中真正使用集成安全性 - 使用SQL身份验证允许您选择一个SQL用户(与PC用户不同),该用户具有足够的权限来完成您的应用程序所需的工作,而不再需要 - 这有助于保护你的数据库。



看看这里:简单的SQL连接字符串创建 [ ^ ] - 它可以帮助您生成一个可以工作的字符串。

Hi;

I have a C# program that connects the sql server database.
I can connect this database with this connection string on my computer;

"Data Source= DESKTOP-E0NKE43\\MYINSTANCE; Database= MYDB; Integrated Security= True;"


But when I put this program to another PC, I cannot connect with this connection string.

My sql server instance is visible to other computers, so what can I do?


Thanks.

P.S: The PC that I'm trying to connect is in the same network on sql server.
P.S1: I haven't try to create a new login user on sql server yet, because I assume Windows Authentication is fine for local computers.

What I have tried:

I enabled the sql server to allow incoming requests. And I'm very sure that sql server instance is visible from other computers because my program checks and list all available sql server instances. I check that using PowerShell too.
I tried the change my connection string Data Source with my computer name, my IP address etc.

解决方案

"Integrated security" is probably your problem, if the DB is still on the same PC as it was - the user on the "new" machine probably isn't authorised to access your computer.

You shouldn't really use integrate security in production anyway - using SQL authentication allows you to select an SQL user (which is not the same as a PC user) that has just sufficient privileges to do the job your app needs, and no more - which can help to protect your DB.

Have a look here: Simple SQL Connection String Creation[^] - it may help you generate a string that will work.


这篇关于连接SQL Server数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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