"附加自动命名的数据库文件*文件名*失败和QUOT的尝试;从ASP.NET开发服务器移动到IIS错误后文件名、数据库文件、错误、服务器

2023-09-06 14:04:27 作者:寂寞陪衬.

我的ASP.NET项目在App_Data文件夹中的MDF数据库。

My ASP.NET project has an MDF database in App_Data folder.

连接字符串为:

数据   源= \ SQLEX $ P $干燥综合征; AttachDbFilename = | DataDirectory目录| \ MainDatabase.mdf;集成   安全=真;用户实例=真

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MainDatabase.mdf;Integrated Security=True;User Instance=True

它工作得很好,直到我改变了项目参数使用本地IIS Web服务器,而不是Visual Studio开发服务器。

It worked fine until I changed the project parameters to use "Local IIS Web server" instead of "Visual Studio Development Server".

该项目现在产生以下 SQLEXCEPTION

附加自动命名的数据库文件的尝试   C:\ Users \用户管理\文档\ Visual Studio中   2010 \项目\ SL \ SL \ App_Data文件\ MainDatabase.mdf   失败。具有相同名称数据库存在,或指定的文件无法   打开,或它位于UNC共享。

An attempt to attach an auto-named database for file C:\Users\Admin\documents\visual studio 2010\Projects\SL\SL\App_Data\MainDatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

如何修改连接字符串,使其与IIS的工作?

How to modify the connection string to make it work with IIS?

推荐答案

由于您使用的是集成安全性,连接必须映射到SQL Server登录用户。当您更改到IIS,你切换用户,它可能不会映射到数据库的登录。你可以通过指定一个用户名和密码,在你的数据库中有效的测试。

Since you are using Integrated Security, the user connecting has to map to a SQL Server login. When you changed to IIS, you switched the user and it may not map to a login in the DB. You could test this by specifying a username and password that are valid in your database.

例如:

数据源= \ SQLEX $ P $干燥综合征; AttachDbFilename = | DataDirectory目录| \ MainDatabase.mdf;用户ID =管理员;密码=密码;用户实例=真

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MainDatabase.mdf;User Id=admin;Password=password;User Instance=True