基本上,每次我运行我的游戏MS数据库时,都会崩溃并返回此错误消息。
无法打开登录请求的数据库“C:\USERS\ME\SOURCE\REPOS\名为LORRY\一个女孩名为LORRY\DATABASE.MDF”。登录失败。用户“me-PC\me”登录失败。
我没有更改项目中的任何SQL或C#代码以导致此错误。我所做的只是通过添加一个类型为string的新列来修改数据库中的一个表。
我尝试使用SMSS在我的项目中打开我的DataBase.mdf文件,以查看我的用户是否有访问它的权限,但是我无法打开我的DataBase.mdf文件,因为它甚至不会在SMSS中出现。因此,我不知道如何才能再次获得访问数据库的权限。我还尝试删除添加到DB中的所有更改,这些更改首先导致错误,但是错误仍然存在。
正如我已经说过的,这个错误是由修改我的数据库中的一个表引起的,但是当我试图打开数据库以删除数据时,有一小部分代码会导致游戏崩溃:
//this method is used to initialize the database.
public static void createSave() {
//database stuff:
con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\me\\source\\repos\\A Girl Called Lorry\\A Girl Called Lorry\\Database.mdf;Integrated Security=True");
adp = new SqlDataAdapter();
ds = new DataSet();
Console.WriteLine("we are in!");
//the below code only initializes if isNewGame is set to true.
removeAllFromInventory();
rewriteCurrentObjects();
loadDefaultNpcs();
}
//removeAllFromInventory is where it crashes.
//removes all items from inventory:
public static void removeAllFromInventory() { //this only applies if
//isNewGame is set to true since we want to wipe the inventory in a new game
if (!isNewGame) return;
con.Open(); //here is where it crashes.
adp.SelectCommand = new SqlCommand("DELETE FROM curInventoryItems", con);
adp.SelectCommand.ExecuteNonQuery();
con.Close();
}发布于 2019-09-03 11:06:21
但是,我无法打开我的DataBase.mdf文件,因为它甚至不会出现在SMSS中。因此,我不知道如何才能再次获得访问数据库的权限。我还尝试删除添加到DB中的所有更改,这些更改首先导致错误,但是错误仍然存在。
在您的问题中有令人困惑的部分,当您无法连接.MDF时,如何删除添加到DB中的更改。
但是,以下步骤可能有助于使数据库恢复正常:
me-PC\me)对C:\USERS\ME\SOURCE\REPOS\A GIRL CALLED LORRY\A GIRL CALLED LORRY\DATABASE.MDF的权限Database.mdf附加到SQL引擎中。您可以使用以下命令通过SSMS执行此操作"Data Source=Localhost\\SQLEXPRESS;Initial Catalog=YourNewDBName;Integrated Security=True"。--- You need to move "Database.mdf" and ".ldf" files into "C"\SQLData" folder before executing the command
CREATE DATABASE YourDatabase
ON (FILENAME = 'C:\SQLData\Database.mdf'),
(FILENAME = 'C:\SQLData\Database_log.ldf')
FOR ATTACH; https://stackoverflow.com/questions/57766783
复制相似问题