找不到正确的连接字符串 [英] Cannot find correct connection string

查看:124
本文介绍了找不到正确的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i在Visual Studio 2015后端SQL Server 2014中有这个C#项目。

当我尝试在另一台PC上运行时连接字符串不会工作。我用Google搜索并找到

https://www.connectionstrings.com/sql-server-2014/

很有帮助,但我不知道我在做什么错了。



我尝试过:



在我的机器上正常工作的连接字符串是:

< pre> string str = @Data Source =(LocalDB)\ MSSQLLocalDB; AttachDbFilename = C:\Users\xpert \Documents\RFID_DB.mdf; Integrated Security = True; Connect Timeout = 30;





i已在客户端PC上安装并更新了正确版本的SQL。请帮助我使用正确的连接字符串。

解决方案

嗯,不 - 它不会工作!

首先, LocalDB 是一个特定的名称,意思是在这台电脑上 - 除非您在两台计算机上安装了SQL Server(我不建议这样做),否则连接字符串必须引用运行SQL Server实例的特定计算机,该计算机包含您需要连接的数据库。

其次,您只附加数据库进行开发 - 您无法在生产中附加数据库,因为完整SQL服务器不支持它。您应该正确地将数据库添加到SQL,并连接到它,除非您正在开发软件,否则永远不要尝试附加。

第三,集成安全性可能是一个问题 - 除非您特别允许域访问目标计算机,它将无法正常工作。无论如何,这是一个坏主意,您应该只创建具有相关权限的用户:INSERT行,UPDATE行,DELETE行。集成安全性提供完全权限,这意味着他们可以编辑或删除数据库中的表。



我们无法准确告诉您使用的内容:我们不会可以访问您的局域网。

但这些是我用于本地访问的两个字符串:

连接=数据源= GRIFF-DESKTOP \\ \\ SQLEXPRESS;初始目录= {0};集成安全性=真



我的平板电脑:

连接=数据Source = GRIFF-DESKTOP \ SQLEXPRESS; Initial Catalog = {0}; Persist Security Info = True; User ID = MyUserName; Password = MyUserPassword 

其中{0}替换为DB名称。


Hi,

i have this C# project in visual studio 2015 backend SQL Server 2014.
when i try to run on another PC the connection string wont work.i googled and found

"https://www.connectionstrings.com/sql-server-2014/"

helpful but i dont know what i am doing wrong.

What I have tried:

the connection string which works fine on my machine is :

<pre>   string str = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\xpert\Documents\RFID_DB.mdf;Integrated Security=True;Connect Timeout=30";



i have installed and updated correct version of SQL on Client PC.Please help me with the correct connection string.

解决方案

Well, no - it won't work!
Firstly, LocalDB is a specific name which means "on this computer" - and unless you have installed SQL Server on both computers (which I don't recommend) the connection string must refer to the specific computer running the instance of SQL server holding the database you need to connect to.
Secondly, you only attach databases for development - you cannot attach a DB in production as "full" SQL server doesn't support it. You should add the DB to SQL properly, and connect to it, never try to attach except when you are developing the software.
Thirdly, Integrated security may well be a problem - unless you have specifically permitted your domain to access the "target" computer, it won't work. And it's a bad idea anyway, you should create users with only the relevant permissions: INSERT row, UPDATE row, DELETE row. Integrated security gives full permissions, which means that they can edit or delete tables in your DB.

We can't tell you exactly what to use: we don't have access to your LAN.
But these are the two strings I use for my local access:

Connection=Data Source=GRIFF-DESKTOP\SQLEXPRESS;Initial Catalog={0};Integrated Security=True


And my tablet:

Connection=Data Source=GRIFF-DESKTOP\SQLEXPRESS;Initial Catalog={0};Persist Security Info=True;User ID=MyUserName;Password=MyUserPassword

Where {0} is replaced with the DB name.


这篇关于找不到正确的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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