“C:\USERS\ME\DATABASE.MDF"由登录请求.登录失败.用户“me-PC\me"登录失败 [英] "C:\USERS\ME\DATABASE.MDF" requested by the login. The login failed. Login failed for user 'me-PC\me'

查看:26
本文介绍了“C:\USERS\ME\DATABASE.MDF"由登录请求.登录失败.用户“me-PC\me"登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上每次我运行游戏时 MS SQL 数据库都会崩溃并返回此错误消息.

Basically every time I run my game MS SQL database crashes and returns this error message.

无法打开登录请求的数据库C:\USERS\ME\SOURCE\REPOS\A GIRL CALLED LORRY\A GIRL CALLED LORRY\DATABASE.MDF".登录失败.用户me-PC\me"登录失败.

Cannot open database "C:\USERS\ME\SOURCE\REPOS\A GIRL CALLED LORRY\A GIRL CALLED LORRY\DATABASE.MDF" requested by the login. The login failed. Login failed for user 'me-PC\me'.

我没有更改项目中的任何 SQL 或 C# 代码来导致此错误.我所做的只是通过添加一个字符串类型的新列来修改我数据库中的一个表.

I did not change any of the SQL or C# code in my project to cause this error. All I did was simply modify a table within my database by adding a new column of type string.

我尝试使用 SMSS 在我的项目中打开我的 DataBase.mdf 文件,以查看我的用户是否有权访问它,但是我无法打开我的 DataBase.mdf 文件,因为它甚至不会出现在 SMSS 中.所以我不确定如何获得再次访问我的数据库的权限.我还尝试删除我添加到数据库中的所有更改,这些更改首先导致错误,但错误仍然存​​在.

I've tried using SMSS to open my DataBase.mdf file within my project to see if my user has privileges to access it, however I was unable to open my DataBase.mdf file because it wouldn't even show up within SMSS. So I'm not sure how I can get privileges to access my database again. I also tried removing all the changes I've added to the DB which caused the error in the first place however the error still persists.

正如我所说,错误是由修改我的数据库中的表引起的,但是有一小段代码在我尝试打开数据库以删除数据时游戏崩溃了:

As I've said, the error was caused by modifying a table within my database, but there is a small piece of code where the game crashes as soon as I attempt to open the database to remove data:

//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();
    }

推荐答案

但是我无法打开我的 DataBase.mdf 文件,因为它甚至不会出现在 SMSS 中.所以我不确定如何获得再次访问我的数据库的权限.我还尝试删除我添加到数据库中的所有更改,这些更改首先导致错误,但错误仍然存​​在.

However I was unable to open my DataBase.mdf file because it wouldn't even show up within SMSS. So I'm not sure how I can get privileges to access my database again. I also tried removing all the changes I've added to the DB which caused the error in the first place however the error still persists.

您的问题中有令人困惑的部分,当您无法连接 .MDF 时,您如何删除添加到数据库中的更改.

There is confusing part in your question, when you unable to connect .MDF how could you remove changes that was added into DB.

但是,以下步骤可能有助于让您的数据库恢复正常:

However, following steps might be helpful to get your database back to normal:

  1. 验证帐户 (me-PC\me) 对 C:\USERS\ME\SOURCE\REPOS\A GIRL CALLED LORRY\A GIRL CALLED LORRY\DATABASE.MDF 具有权限
  2. 如果权限后不起作用,您可以对 SQL Localdb 连接进行故障排除 使用这些步骤
  3. 安装 SQL Express(因为使用 LocalDB 数据库引擎很难管理),并将 Database.mdf 附加到 SQL Express 引擎中.您可以通过 SSMS 使用以下命令执行此操作
  4. 在 SQL Express 准备好数据库后,您可以将连接字符串更改为 "Data Source=Localhost\\SQLEXPRESS;Initial Catalog=YourNewDBName;Integrated Security=True"
  5. 如果即使使用 SQL Express 也有问题,您可以按照以下步骤操作..
  1. Verify the account (me-PC\me) has permissions on C:\USERS\ME\SOURCE\REPOS\A GIRL CALLED LORRY\A GIRL CALLED LORRY\DATABASE.MDF
  2. If doesn't work after the permissions, you can troubleshoot the SQL Localdb connections using these steps
  3. Install SQL Express (as it's difficult to manage with LocalDB database engine), and attach Database.mdf into SQL Express engine. You can do this using following command via SSMS
  4. Once your database ready at SQL Express, you can change your connection string to "Data Source=Localhost\\SQLEXPRESS;Initial Catalog=YourNewDBName;Integrated Security=True"
  5. In case issue even with SQL Express, you may follow these steps..

--- 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;  

这篇关于“C:\USERS\ME\DATABASE.MDF"由登录请求.登录失败.用户“me-PC\me"登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆