开发者

Unable to connect to SQL database in AppData when deployed to web server

开发者 https://www.devze.com 2023-02-18 04:17 出处:网络
I have a ASP.Net program written in C# that uses a database stored in the AppData directory, the program works perfectly on my development (Win7\\SQL 2008R2) when I deploy to a Win2008R2\\SQl 2008 R2

I have a ASP.Net program written in C# that uses a database stored in the AppData directory, the program works perfectly on my development (Win7\SQL 2008R2) when I deploy to a Win2008R2\SQl 2008 R2 server the program is unable to 开发者_开发知识库connect to the database. I'm using the connection string below. Several sites suggest I set the Application Pool to use 'Network Service' as this has Modify permission to the AppData directory, I have done this but it still won't work, another site suggested I Application Pool to "Load User Profile = True" but still no joy.

I'm pulling my hair out with what else to try, can anyone help?

data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\DB.mdf;User Instance=true

I get "Object reference not set to an instance of an object." in my app and "An attempt to attach an auto-named database for file C:\inetpub\wwwroot\ADPhonebook\App_Data\DB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share." in the Application Event Log

I really appreciate any advice, thanks. Steven


As Martin points out in the comments, it would be interesting if you posted the exact error message (and maybe the full exception detail) you are getting.

But problems like this have mostly to do with rights at the OS level.

So make sure that the user (identity) of the Application Pool has full access (ntfs) rights to the .mdf file, and try again.

Edit (after you posted the exact message):
Ok, I guess this means that on the server you're deploying to, there is already a database called DB on that Sql Server instance. So you will have to remove or rename that one in order to be able to attach a database with that name.
I think the user rights problem is also still possible though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号