简体   繁体   English

无法访问其他计算机上的SQL Server数据库

[英]Unable to access SQL Server database on a different machine

I'm developing an asp.net mvc application at my office. 我在办公室开发一个asp.net mvc应用程序。 I wanted to work at home as well, so, I pushed my project on github, when I came my home back, I pulled it from github to my projects folder, now I tried to access its SQL Server database in server explorer using windows authentication, on pressing ok, it showed me the following error : 我也想在家工作,所以,我将项目推送到github上,当我回到家时,我将其从github拖到我的项目文件夹中,现在我尝试使用Windows身份验证在服务器资源管理器中访问其SQL Server数据库,按OK时,它显示了以下错误:

Cannot open database "HrAndPayrollSystem.Models.HrAndPayroll" requested by the login. 无法打开登录请求的数据库“ HrAndPayrollSystem.Models.HrAndPayroll”。 The login failed. 登录失败。

Login failed for user 'user'. 用户“ user”的登录失败。

and here is my connection string : 这是我的连接字符串:

<connectionStrings><add name="HrAndPayroll" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=HrAndPayrollSystem.Models.HrAndPayroll;Integrated Security=False" providerName="System.Data.SqlClient" />

What could be the reason, how should I resolve it? 原因可能是什么,我应该如何解决? Thanks in Advance :) 提前致谢 :)

So, I somehow managed to get through this. 因此,我设法做到了这一点。

In other words, this error says that you need to access your database at least for a single time, means you need to perform some transactions with the database, inserting something or retrieving something, at this point you accessed the database for the first time on the different machine. 换句话说,此错误表示您至少需要访问一次数据库,这意味着您需要与数据库执行一些事务,插入内容或检索内容,这时您是第一次访问数据库不同的机器。 Since, I had to access database at the point when my application starts, so, crashing start crashes my whole application, so I created another controller that does not contain any authorize attribute, just to leave it open in order to access the database, created a single field, accessed the database, now go and check your database in server explorer, you are about to access it for the first time in the database, and now also, it will never crash anywhere. 因为,我必须在应用程序启动时访问数据库,所以崩溃启动会使整个应用程序崩溃,因此我创建了另一个控制器,该控制器不包含任何授权属性,只是为了访问数据库而将其保持打开状态,一个字段,可以访问数据库,现在在服务器资源管理器中检查数据库,您将第一次在数据库中访问它,现在,它也永远不会崩溃。

So, the point is that you need to access your database at least for a first time.. 因此,关键是您至少需要第一次访问数据库。

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

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