2012-07-24 73 views
3

我有一个连接到SQLServer Express数据库文件以用于成员资格和数据存储的网站。因此我有两个.mdf文件。下面是连接字符串:SQLExpress - 如何为sql数据文件设置用户名/密码

public static string ASPNETDB = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf;Integrated Security=True;User Instance=True;User ID=;Password=; "; 
public static string Dok = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dok.mdf;Integrated Security=True;User Instance=True;User ID=;Password=; "; 

现在删除并重新安装的网站,我在一个连接established.Here的部分已经越来越许多错误后的错误:

Unable to open the physical file "C:\Inetpub\wwwroot\BSHHD\App_Data\aspnetdb_log.ldf". 
Operating system error 5: "5(failed to retrieve text for this error. Reason: 1815)". 
Cannot open user default database. Login failed. 
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. 
File activation failure. The physical file name "C:\Inetpub\wwwroot\BSHHD\App_Data 
\aspnetdb_log.ldf" may be incorrect. 
The log cannot be rebuilt because there were open transactions/users when the database 
was shutdown, no checkpoint occurred to the database, or the database was read-only. 
This error could occur if the transaction log file was manually deleted or lost due to 
a hardware or environment failure. 

这是非常奇怪,因为我没有对网站做任何改变。我刚刚从IIS中删除它并重新安装它。我被建议设置用户名和密码,并删除集成安全。但我不知道如何为数据文件设置用户名/密码。

回答

7

添加数据库ASPNETDB.MDF到的SQL Express与SQL Management Studio中 你可以从微软Web平台安装程序下载。

打开SQL Management Studio中 右键单击数据库>连接>添加MDF和日志文件(优先,你把他们其他地方,那么网站目录。

在MSSQL中,你可以轻松地设置用户名和密码,打开SQL Management Studio中

登录到管理工作室: 展开安全性>登录>写点击登录 “新登录”

登录名:例如LogMeIn的 让它SQL Server身份验证 设置密码 删除强制

在左边,你将有用户映射 选择要连接到并给予写权限,例如数据库,如果此用户可以写入到数据库中你将要使它datawriter或db_owner这是更高的权限:

内置角色的数据库是:

公共 - 默认设置授权

的db_owner的 - 允许执行一个指定的数据库

db_oddladmin的任何操作 - 允许创建或修改的数据库的新的对象(所谓的DDL 操作);你应该采取的事实通知用户不必有

的db_owner权限做

的db_datareader - 允许读取任何表

db_datawriter权限 - 允许写任何表

db_denydatareader - 禁止读取的表(一种公开的授权外卖)

dDb_denydatawriter - 禁止写表

将数据库添加到SQL之后: 可以在Web中添加。config

<add name="ASPNETDB" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASPNETDB.mdf;User ID=yourusername;Password=yourpassword" providerName="System.Data.SqlClient" /> 
<add name="Dok " connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dok.mdf;User ID=yourusername;Password=yourpassword" providerName="System.Data.SqlClient" /> 

或者如果您希望在代码中拥有它,就像上面它也可以工作。

Regards, Gabriel

相关问题