在安装程序中装载 SQL Server Express .mdf 文件的最佳方法是什么?

发布于 2024-08-09 19:40:14 字数 129 浏览 4 评论 0原文

安装需要 SQL Server Express 的软件的首选方法是什么?您是否应该使用安装该软件的管理员创建的新帐户来安装数据库?

如果我们使用 SA 帐户,则在安装时没有问题,但在运行时会出现错误,表明 LDF 文件存在问题。

What is the preferred method for installing software that requires SQL Server Express? Should you mount the database using a new account created by an admin that installs the software?

If we use the SA account there is no problem at install time, but at runtime there is an error indicating an issue with the LDF file.

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

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

发布评论

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

评论(2

别理我 2024-08-16 19:40:14

谢谢斯科特提出的精彩问题。确保 SQLExpress 对包含数据文件的部署文件夹具有读、写、修改访问权限。接下来,您需要确保访问您的应用程序的所有用户都可以修改数据。您可以授予完全访问权限,但不建议这样做。相反,创建一个本地 SQL 用户帐户并授予该用户修改数据库的能力。接下来确保 SQL 实例已设置为混合模式登录
作者:

"USE [master] " & _
            "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2 "

如果 SQL 用户有能力修改目录,上面将创建该日志文件!

现在授予创建的用户:

 "CREATE Login UName WITH PASSWORD = 'UPassword', DEFAULT_DATABASE=[MyDatabase], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF;  " & _
        "exec sp_addsrvrolemember N'UName', sysadmin; "

现在将该用户添加到您希望的所有角色,例如:

"USE [MyDatabase]  " 
"EXEC sp_addrolemember N'db_datareader', N'User' "

您可以选择对该用户执行其他操作。但这取决于您想要实现的目标。

最后一步是通过以下方式使用此新帐户连接您的应用程序:

连接字符串:

Data Source=***********\SQLEXPRESS;AttachDbFilename=****\Datafile.mdf;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=UNAME;Password=UPassword" />

Thank you Scott for your excellent question. Ensure that SQLExpress has read, write, modify access to the deployment folder which contains the datafile. Next you need to make sure that all users who access your application may modify the data. You could grant full access, but this is not advised. Instead create a local SQL user account and grant the user the ability to modify your database. Next ensure that the SQL instance has been set up to a mixed mode login
By:

"USE [master] " & _
            "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2 "

The above will create that log file if the SQL users have the ability to modify the directory!!

Now grant the user created By:

 "CREATE Login UName WITH PASSWORD = 'UPassword', DEFAULT_DATABASE=[MyDatabase], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF;  " & _
        "exec sp_addsrvrolemember N'UName', sysadmin; "

Now add that user to all the roles you wish, example:

"USE [MyDatabase]  " 
"EXEC sp_addrolemember N'db_datareader', N'User' "

There are other actions which you may choose to take on the user. But this depends on what your trying to accomplish.

The last step is to connect your application using this new account by:

Connection string:

Data Source=***********\SQLEXPRESS;AttachDbFilename=****\Datafile.mdf;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=UNAME;Password=UPassword" />
椵侞 2024-08-16 19:40:14

我应该说“如果 SQL 用户有能力修改目录,上面将创建该日志文件!!”
在运行时以管理员身份执行该代码的行为将创建日志文件;)

I should say "The above will create that log file if the SQL users have the ability to modify the directory!!"
The act of executing that code as the administrator at run time will create the log file ;)

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