C# 无法打开登录请求的数据库“”。登录失败。用户“sa”登录失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15061836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open database "" requested by the login. The login failed. Login failed for user 'sa'
提问by Rika
UPDATE3:
Since no one answered my first problem as suggested by @Timen i tried using the SQL SERVER Authentication.
I Enabled the SQL Authentication
through SQL SERVER MANAGEMENT STUDIO
and enabled sa
and set a simple password for it.(under .\sqlexpress).
I can Successfully log in to the database by sa
and its password from SQL SERVER MANAGEMENT STUDIO
but when i try to do so from my application it fails with this error message :
更新3:
由于没有人按照@Timen 的建议回答我的第一个问题,我尝试使用 SQL SERVER 身份验证。
我启用了SQL Authentication
通过SQL SERVER MANAGEMENT STUDIO
并启用sa
并为其设置了一个简单的密码。(在 .\sqlexpress 下)。我可以通过以下方式成功登录数据库sa
及其密码,SQL SERVER MANAGEMENT STUDIO
但是当我尝试从我的应用程序登录时,它失败并显示以下错误消息:
Cannot open database "dbNegin" requested by the login. The login failed. Login failed for user 'sa'.
无法打开登录请求的数据库“dbNegin”。登录失败。用户“sa”登录失败。
I need to say that i changed the database owner to sa as well , yet i get this error!! How can i solve this now? :( By the way this is the connection string used in my application to connect to the database :
我需要说我也将数据库所有者更改为 sa ,但我收到此错误!!我现在如何解决这个问题?:(顺便说一下,这是我的应用程序中用于连接到数据库的连接字符串:
string sqlconstring = @"Data Source=.\sqlexpress;User ID=sa;Password=123456;Initial Catalog=dbNegin";
string sqlconstring = @"Data Source=.\sqlexpress;User ID=sa;Password=123456;Initial Catalog=dbNegin";
My data base is attached by the way (its located in the address below )
顺便附上我的数据库(它位于下面的地址中)
D:\TestDb\Debug\dbNegin.mdf
D:\TestDb\Debug\dbNegin.mdf
This is the SQL Error log:
这是 SQL 错误日志:
2013-02-25 21:51:20.80 spid51 Starting up database 'C:\USERS\FRIEND\DESKTOP\RELEASE\DBNEGIN.MDF'.
2013-02-25 21:51:21.33 spid51 Starting up database 'mytestdb'.
2013-02-25 21:51:21.60 spid51 Starting up database 'C:\USERS\FRIEND\DESKTOP\RELEASE\DBNEGIN.MDF'.
2013-02-25 21:51:35.60 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 21:51:35.60 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2013-02-25 22:11:00.79 Server Server resumed execution after being idle 246 seconds: user activity awakened the server. This is an informational message only. No user action is required.
2013-02-25 22:11:00.97 spid51 Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2013-02-25 22:11:01.04 spid51 Using 'xplog70.dll' version '2007.100.1600' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.
2013-02-25 22:57:29.06 spid53 Starting up database 'C:\USERS\FRIEND\DESKTOP\RELEASE\DBNEGIN.MDF'.
2013-02-25 22:58:40.51 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 22:58:40.51 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2013-02-25 23:07:09.86 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 23:07:09.86 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2013-02-25 23:07:16.37 Logon Error: 18456, Severity: 14, State: 38.
2013-02-25 23:07:16.37 Logon Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
Old QuestionI am trying to connect to a database in two modes ( on my system the database is located under the SQLSERVER Data subfolder whereas in my customer system i want it to be next to my executable.For this i have two connection strings one for my own system which is :
老问题我试图以两种模式连接到数据库(在我的系统上,数据库位于 SQLSERVER Data 子文件夹下,而在我的客户系统中,我希望它位于我的可执行文件旁边。为此,我有两个连接字符串,一个用于我自己的系统是:
"Data Source=.\SQLExpress;Initial Catalog=dbNegin;Integrated Security=True"
“数据源=.\SQLExpress;初始目录=dbNegin;集成安全性=True”
And one for the customer machine:
还有一个用于客户机器:
"Data Source=.\SQLExpress;AttachDbFilename=C:\Users\Master\Documents\Visual Studio 2010\Projects\ProjectNegin\ProjectNegin\bin\Debug\dbNegin.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
"Data Source=.\SQLExpress;AttachDbFilename=C:\Users\Master\Documents\Visual Studio 2010\Projects\ProjectNegin\ProjectNegin\bin\Debug\dbNegin.mdf;Integrated Security=True;Connect Timeout=30;User Instance=真的”
, The problem is i tried to test the second scenario on my system, I placed the latest Database next to my executable and changed the connection string and tried to run the application,For some sections of the application it connects to the database and retrieves information , but on some others it failes with this error:
,问题是我试图在我的系统上测试第二个场景,我将最新的数据库放在我的可执行文件旁边并更改了连接字符串并尝试运行应用程序,对于应用程序的某些部分,它连接到数据库并检索信息,但在其他一些情况下,它会因以下错误而失败:
Cannot open database "dbNegin" requested by the login. The login failed. Login failed for user 'Master-PC\Master'.
无法打开登录请求的数据库“dbNegin”。登录失败。用户“Master-PC\Master”登录失败。
Master-PC\Master
is the name of my computer! I don't remember using it in my connection string and have no idea where it came from and how i can get rid of it.To be even worst, now my former connection string fails as well with this error !!.
I need to say this that before i try the my second connection string (the one next to executable file) i renamed the database inside SQLSERVER
DATA
sub folder so that i don't miss anything and i can only connect to the database through atatchfile method (to avoid the possible probable connection to the to my default database connection string)
When i tried to use my former connection string, i renamed back my database to its original name (i mean the one inside DATA sub folder ) . but i am still getting this error .
How can i solve this problem ?
Master-PC\Master
是我电脑的名字!我不记得在我的连接字符串中使用它,也不知道它来自哪里以及如何摆脱它。更糟糕的是,现在我以前的连接字符串也因此错误而失败!!
我需要说的是,在尝试第二个连接字符串(可执行文件旁边的字符串)之前,我将SQLSERVER
DATA
子文件夹内的数据库重命名,这样我就不会错过任何内容,并且我只能通过 atatchfile 方法连接到数据库(以避免可能的连接到我的默认数据库连接字符串)当我尝试使用我以前的连接字符串时,我将我的数据库重命名回其原始名称(我的意思是 DATA 子文件夹中的那个)。但我仍然收到此错误。我怎么解决这个问题 ?
UPDATE
:
When i tried using SQL SEVER MANAGEMENT STUDIO
to see my database the database reads as:
UPDATE
:当我尝试使用SQL SEVER MANAGEMENT STUDIO
查看我的数据库时,数据库显示为:
(Recovery Pending...)
(恢复等待中...)
and I cant do anything about it ( since it says it must be either repaired or dropped! and i cant find a repair menu !)
我对此无能为力(因为它说必须修理或丢弃!而且我找不到修理菜单!)
UPDATE 2:
I tried deleting the database form Management Studio and re attaching it ! After deleting it form the database lists in Management studio.
Now I can't re attach it again i get the error :
UPDATE 2:
我尝试删除数据库表单 Management Studio 并重新附加它!将其从 Management Studio 中的数据库列表中删除后。
现在我无法重新附加它,我收到错误:
TITLE: Microsoft SQL Server Management Studio
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476
------------------------------ ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\New folder\dbNegin.mdf'. (Microsoft SQL Server, Error: 5123)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=10.00.2531&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476
标题:Microsoft SQL Server 管理工作室
无法检索此请求的数据。(Microsoft.SqlServer.Management.Sdk.Sfc)
如需帮助,请单击:http: //go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476
- - - - - - - - - - - - - - - 附加信息:
执行 Transact-SQL 语句或批处理时发生异常。(Microsoft.SqlServer.ConnectionInfo)
CREATE FILE 在尝试打开或创建物理文件 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\New folder 时遇到操作系统错误 5(无法检索此错误的文本。原因:15105) \dbNegin.mdf'。(Microsoft SQL Server,错误:5123)
如需帮助,请单击:http: //go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=10.00.2531&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476
采纳答案by Rika
This Topic Answered My Question : you can find good information there :
The Cause For This Problem And How to Solve It .
This is the page ScreenShot:
本主题回答了我的问题:您可以在那里找到很好的信息:
此问题的原因以及如何解决。
这是页面截图:
回答by NiteshG86
If you are using LAN connection between you and your customer, use this connection string.
如果您和您的客户之间使用 LAN 连接,请使用此连接字符串。
"Data Source=Master-PC\Master;;Initial Catalog=dbNegin;Integrated Security=True;Connect Timeout=30;User Instance=True"
or
或者
"Data Source=Master-PC\Master\SQLExpress;Initial Catalog=dbNegin;Integrated Security=True;Connect Timeout=30;User Instance=True"
For data source you can also use IP Address of your PC. This will help u.
对于数据源,您还可以使用 PC 的 IP 地址。这将帮助你。
回答by Timon
instead of windows authentication try sqlserver authentication mode .... this may work for u..
而不是 Windows 身份验证尝试 sqlserver 身份验证模式 .... 这可能适用于你..
回答by user2213865
Change your connections string only!!
只更改您的连接字符串!!
Nooo
努
- delete tour connections string
- create password for SQL server authentication
- create new form
- add datagrid viwer
- connect you datagrid viwer with database by your password created
- 删除旅游连接字符串
- 为 SQL 服务器身份验证创建密码
- 创建新表格
- 添加数据网格查看器
- 通过您创建的密码将您的数据网格查看器与数据库连接起来
Now tour app.config generation new connection string and database identifier inside by password
现在通过密码浏览 app.config 生成新的连接字符串和数据库标识符
If you change your connections string only not working
如果您仅更改连接字符串则不起作用