如何在Windows窗体应用程序中同时与数据库多个连接

问题描述:

我们如何共享数据库意味着我们如何同时为两个相同的软件使用相同的数据库?

我的工作

i在两台 PC 之间制作服务器并共享我的.mdf和.ldf文件

然后我安装尝试在 PC上运行我的项目在同一时间但却抛出错误登录失败

请帮我完成我的项目

谢谢你



我尝试过:



用于连接我用过这个

how can we share data base means how can we use same database at same time for two same software ?
My working
i made server between two PC and share my .mdf and .ldf files
then i install try to run my project on both PC at same time but it throw an error "login fail"
please help me to complete my project
THANK YOU

What I have tried:

for connection i used this

<appsettings><br />
    <add key="con" value="Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\MTS\database\MTS.mdf;Integrated Security=True;Connect Timeout=30" /><br />
  </appsettings>

您正在尝试附加一个特定PC的本地数据库 - 它位于D驱动器上。

除非您以某种方式设法连接相同的硬盘驱动器到两台PC,这是不可能的...

而不是附加你的MDF,在SQL Server实例中创建数据库,让SQL Server处理保存的位置它。

我强烈建议集成安全性是一个坏主意:创建SQL服务器用户,并以其中一个登录。这样,您可以限制用户应用程序对数据的访问。例如,如果您的应用程序容易受到SQL注入的影响,您可以拒绝DROP TABLE请求。
You are trying to attach a DB which is local to a specific PC - it's on the D drive.
Unless you have somehow managed to connect the same HDD to two PCs, that isn't likely to work...
Instead of attaching your MDF at all, create the database in the SQL Server instance and let SQL Server handle where to keep it.
And I'd strongly suggest that Integrated Security is a bad idea: create SQL server users, and log in as one of those. That way, you can limit the access a user application has o data. For example you can refuse DROP TABLE requests, in case your app is susceptible to SQL Injection.