ASP.NET 应用程序不会与 Sql Server Management Studio Express 共享数据库

发布于 2024-09-27 14:51:36 字数 917 浏览 6 评论 0原文

我有一个 ASP.NET 3.5 应用程序,其 App_Data 文件夹中有一个 SQL 2005 Express .mdf 数据库文件。我们称之为 Foo.mdf。 ASP.NET 应用程序本身可以毫无问题地连接到数据库。到目前为止,一切都很好。

然后,如果我安装 Sql Server Management Studio在服务器上运行 Express 并启动它,它会找到本地 SQLEXPRESS 实例并连接到它,但不会在数据库列表中显示 Foo.mdf。

因此,我尝试通过右键单击数据库并选择 Attach.. 并找到 .MDF 来附加 Foo.mdf。此操作失败并出现模糊错误:

CREATE FILE encountered operating system error 32(error not found)  
while attempting to open or create the physical file
'C:\inetpub\wwwroot\FooApp\App_Data\Foo.mdf'. (Microsoft SQL Server, Error: 5123)

如果我在 IIS 中停止我的 ASP.NET 站点,则附加确实工作,但是当我重新启动 ASP.NET 应用程序时,它无法连接到 Foo。中密度纤维板。

因此,看起来 SQL Express 2005 只会让我的应用程序 Management Studio 连接。这看起来真的很糟糕——Sql Express 肯定应该允许多个连接吗?我期望它的行为像普通的 Sql Server。

希望我做错了。请指教。

I have an ASP.NET 3.5 app with a SQL 2005 Express .mdf database file in its App_Data folder. Lets call that Foo.mdf. On its own the ASP.NET app can connect to the database with no problems. So far so good.

Then, if I install Sql Server Management Studio Express on the server and start it, it finds the local SQLEXPRESS instance and connects to it, but doesn't show Foo.mdf in the list of databases.

So I try and Attach Foo.mdf by right-clicking on databases and selecting Attach.. and finding the .MDF. This fails with a vague error:

CREATE FILE encountered operating system error 32(error not found)  
while attempting to open or create the physical file
'C:\inetpub\wwwroot\FooApp\App_Data\Foo.mdf'. (Microsoft SQL Server, Error: 5123)

If I stop my ASP.NET site in IIS, then the attach does work, but then when I restart my ASP.NET app, it can't connect to Foo.mdf.

So it looks like SQL Express 2005 will only let either my app or Management Studio connect. This seems really crap - surely Sql Express should allow more than one connection? I was expecting it to behave like regular Sql Server.

Hopefully I'm doing it wrong. Please advise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长途伴 2024-10-04 14:51:36

您可以检查您的应用程序连接字符串并查看它是否具有 User Instance=true

例如:

Data Source=.\SQLEXPRESS;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;

来自 MSDN:用户实例的另一个主要问题是因为 SQL Server 以独占访问权限打开数据库文件。这是必要的,因为 SQL Server 管理其内存中数据库数据的锁定。因此,如果多个 SQL Server 实例打开同一文件,则可能会出现数据损坏。如果两个不同的用户实例使用相同的数据库文件,则一个实例必须先关闭该文件,然后另一个实例才能打开该文件。

如果这是问题所在,那么您可以在 SQL Server Management Studio 中附加数据库并按如下方式修改连接字符串,以便多个客户端可以连接到同一数据库。

Server=.\SQLEXPRESS;Database=myDataBase;Trusted_Connection=True;

如果这不是您遇到的问题,另请查看上面链接中的“常见问题”部分。根据“常见问题”部分中的第 1 / 2 点,它可能与权限有关

Can you check your application connection string and see if it has User Instance=true

eg :

Data Source=.\SQLEXPRESS;Integrated Security=true; AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;

From MSDN : The other main issue with user instances occurs because SQL Server opens database files with exclusive access. This is necessary because SQL Server manages the locking of the database data in its memory. Thus, if more than one SQL Server instance has the same file open, there is the potential for data corruption. If two different user instances use the same database file, one instance must close the file before the other instance can open it.

If that is the issue, then you can attach the database in SQL Server Management Studio and modify the connection strings as follows so that multiple clients can connect to the same database.

Server=.\SQLEXPRESS;Database=myDataBase;Trusted_Connection=True;

If this isnt the issue in your case, also check out the "Common Issues" section at the link above. It could be related to permissions as per points 1 / 2 in the "Common Issues" section

梦亿 2024-10-04 14:51:36

我没有任何使用默认 ASP.NET 数据库的经验,但您是否尝试过将 MDF 移动到 SQL Express DATA 文件夹? (默认值:C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA)进入该文件夹后,您可以使用 Management Studio 将文件附加到 SQL Express 实例。您需要修改 web.config 文件中的连接字符串,如下所示:

<connectionStrings>
    <add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=aspnetdb"
     providerName="System.Data.SqlClient" />
</connectionStrings>

I don't have any experience using the default ASP.NET database, but have you tried moving the MDF to your SQL Express DATA folder? (default: C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA) Once in the folder you can use the Management Studio to attach the file to your SQL Express instance. You'll want to modify your connection string in your web.config file to look like this:

<connectionStrings>
    <add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=aspnetdb"
     providerName="System.Data.SqlClient" />
</connectionStrings>
忘东忘西忘不掉你 2024-10-04 14:51:36

将以下用户帐户添加到您网站的 *App_Data* 文件夹中:SQLServerMSSQLUser$。在高级安全权限中查找它,因此您可以在那里进行搜索,然后对其进行完全控制。

Add the following user account to the folder *App_Data* of your website: SQLServerMSSQLUser$. Look for it in the advanced security permissions, so you do a search there and then give full control to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文