Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

localdb - Is there a way to prevent SQL Server resetting itself back to read-write mode?

I'm working on an application which automatically attaches MDF files and connects to them in SQL Server LocalDB. I need to allow scenarios where each user has their own SQL Server LocalDB instance on the same computer, and all the instances attach to the same MDF file. I realised I could do this by making the database read-only: ALTER DATABASE MyDatabase SET READ_ONLY.

However, the database sometimes resets itself to read-write mode when the application (and I, in SSMS) connect or disconnect. This seems to be because auto-close is enabled. When I run ALTER DATABASE MyDatabase SET AUTO_CLOSE OFF, I no longer get the problem.

When I try the same in another edition of SQL Server, I don't see the same behaviour. Maybe there is something special about LocalDB. However, I do need to use LocalDB.

Is there a way to stop this odd resetting behaviour without disabling auto-close?

Are there significant drawbacks to having a large number of databases on the same computer with auto-close disabled?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...