成功地与服务器建立了连接,但是在登录过程中发生了一个错误(错误号: 233)

连接到 SQLServer 时出错:

enter image description here

堆栈跟踪的详细信息如下:

===================================


Cannot connect to ServerName.


===================================


A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) (.Net SqlClient Data Provider)


------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=233&LinkId=20476


------------------------------
Server Name: ServerName
Error Number: 233
Severity: 20
State: 0




------------------------------
Program Location:


at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService.ValidateConnection(UIConnectionInfo ci, IServerType server)
at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()

注意 我试过了

  • 关闭,重新打开 Sql 服务器 ManagementStudio。

  • 关闭,重新打开 VS 和重建解决方案

  • 死工进程访问数据库。

  • 登录凭据正确。

  • 能够 ping 服务器,以确保它没有关闭。

339503 次浏览

From here:

Root Cause: Maximum connection has been exceeded on your SQL Server Instance.

How to fix it...!

  1. F8 or Object Explorer
  2. Right click on Instance --> Click Properties...
  3. Select "Connections" on "Select a page" area at left
  4. Chenge the value to 0 (Zero) for "Maximum number of concurrent connections(0 = Unlimited)"
  5. Restart the SQL Server Instance once.

Apart from that also ensure that below are enabled:

  • Shared Memory protocol is enabled
  • Named Pipes protocol is enabled
  • TCP/IP is enabled

Turn out to be some SQL service was stopped somehow on server. Restarting SQL Server service manually was the solution.

For SQL2008,

  • open Management Studio
  • Rt click on instance
  • go to properties
  • select Security
  • Under Server Authentication, check SQL Server and Windows Authentication Mode
  • hit OK

Restart the server using configuration manager.

Sometimes specifying the database (instead of default) solves this error.

When you starting application 'Run as administrator'.This way I avoided this error.

enter image description here

SQL 2016 solution/workaround here (could also work in earlier versions). This may not work or be appropriate in every situation, but I resolved the error by granting my database user read/write schema ownership as follows in SSMS:

Database > Security > Users > User > Properties > Owned Schemas > check db_datareader and db_datawriter.

I got that error message in code line containing SqlConnection.Open() running my .NET code as x64 application. Running as x86 causing no errors.

Solution was to deactivate the Force protocol encryption option for TCP/IP in %windir%\System32\cliconfg.exe

Force protocol encryption

the following points work for me. Try:

  1. start SSMS as administrator
  2. make sure SQL services are running. Change startup type to 'Automatic'

enter image description here

  1. In SSMS, in service instance property table, enable below:

enter image description here

I've gotten this error because the user trying to login was lacking permissions.

I don't recommend doing this, but I fixed it by granting the user db_owner globally. It was a local instance, so not a huge security concern.

In my case I had the following by mistake in my connection string:

Encrypt=True

Changing to

Encrypt=False

Solved the problem

"Server=***;Initial Catalog=***;Persist Security Info=False;User  ID=***;Password=***;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=False;Connection Timeout=30;"

My problem resolved by this what changes i have done in .net core Do this changes in Appsetting.json

Server=***;Database=***;Persist Security Info=False;User ID=***; Password=***;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=False;Connection Timeout=30

Do following changes in Package console manager

Scaffold-DbContext "Server=***;Database=***;Persist Security Info=False;User ID=***; Password=***;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=False;Connection Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context DatabaseContext -f

Happy coding

To add on top of @Pranav Singh and @Rahul Tripathi answer. After doing all the mentioned by those 2 users, my .net app still wasnt connecting to the database. My solution was.

Open Sql Server Configuration Manager, go to Network configuration of SQL SERVER, click on protocols, right click on TCP/IP and select enabled. I also right clicked on it opened properties, Ip directions, and scrolled to the bottom (IPAII , and there in TCP Port, I did setup a port (1433 is supposed to be default))

You can also get this error, somewhat unhelpfully, if the database name specified in the connection string doesn't exist. Check your Db Name carefully!

This is what helped me [src]:

File > Connect Object Explorer... > Options (bottom right) > Connection properties tab > Trust Server Certificate tickbox

enter image description here

For me, adding Trusted_Connection=True to the connection string helped.

Here is the solution I found:

Go to SQL Server Management, Disable Memory Shared, TCP/IP and Pipes named.

Restart the server and try again.

I had to do 2 things: Do what Joseph Wu said and change the authentication to be SQL and Windows. But I also had to go to Server Properties > Advanced and change "Enable Contained Databases" to True.

One of the solutions above gave me a clue. The sa account was generating this exact error. I was able to log in with a Windows service account with admin privileges. At some point recently a GPO had been applied to strengthen the password policy. The existing sa password didn't meet the new strengthened password policy.

Log into SQL Server Management Studio with alternative admin credentials. Instance > Security > Logins > account (sa in my case) Untick "Enforce password policy" Click OK. Disconnect and login again with the account.

Worked for me.

HAd to reboot the server to get various jobs running again but if I took time to go through them I probably could have restarted them from the SSMS without a server restart.

I had previously limited the number of connections to my DB to 2. Clearly this was an issue. After restarting the server, login, you will get an error popup and just click OK. Right click on the server in the object explorer, go to properties, go to connection and change your limited number of connections (I went from 2 to 20) everything works fine now.

I appreciate this is an old post. But I came across it today, saw lots on MS forums which were incorrect solutions. Almost all of them on here didn't work for me either.

For MS SQL Management Studio

Options >> connection properties and check Trust Server Certificate option enter image description here

What helped me is deleting .ldf files from \bin\Debug

In my case changing <default> to master under Connection Properties in Options solved the issue.

One possible source of this problem is if the database login is not mapped to a user in the database. Solution is of course simple, map the login to the database user.

Seems like I had a unique situation - other than all the answers posted here.

I connect to the database with a restricted login (mapped to the database user) and NOT the sysadmin sa

Now I restored by database from a copy of another database on the same sql server database (same issue would occur even if you have restored form another sql server database server), but missed to delete the database user and recreated it.

So, essentially, if you are restoring your sql server database here is what you need to do:

  1. Restore the database
  2. Delete any roles owned by the user (that is ultimately mapped to the login which is not working)
  3. Delete the user mapped to the login
  4. Re-map the login to the user
  5. Recreate the role and add the user to that role enter image description here

enter image description here

Create the User in Security. Default database will be set to Master After that, you can log in to SQL Server Authentication.

Same Error with Connection String in Visual Studio dev environment

Our development database server was recently given a self-signed certificate so it automatically became untrusted. This resulted in the login error cited above. I added TrustServerCertificate=True to my connection string and it works now.

"Server=TheServerAddress; Database=TheDataBase; User Id=TheUsername; Password=ThePassword; TrustServerCertificate=True"

Got this error from downloading Microsoft.Data.SqlClient package

removed Microsoft.Data.SqlClient package and it worked.

i got the error after deleting a database. this db was the default db chosen by the mssql management tool. so, the connection was established but because the db was missing, the process resulted in an error. the solution is to change the defaut db to a db that exists. in the connection popup press the 'options' button, and then in the 'connect to database' field, choose one that exists in your sql server. that solved the problem for me. :)

For me the following did the trick:

  • Open SQL Server Configuration
  • On the left under "SQL Server Network Configuration", click on "Protocols for MSSQLSERVER"
  • Then on the right make sure to set "Named Pipes" to Enabled

Restarted my pc. Then could succesfully login again with my sa account.

I'm a little late to the party with this, but I found when I saw this error it was due to the login I was using not having permission to the stored procedure it was trying to execute.

Steps to resolve the issue:

  1. Goto File > Connect Object Explorer.. > Options > Connection Properties: Make sure 'Trust connection certificate' checkbox is checked.

  2. Goto File > Connect Object Explorer.. > Options > Connection Properties: Make sure 'Encrypt connection' check box is unchecked.

  3. Check whether 'SQL Server(MSSQLSERVER)' and 'SQL Server Agent(MSSQLSERVER)' services are running.

  4. Add the following statements in the connection string:

    Trusted_Connection=True;TrustServerCertificate=True;

This way, I was able to resolve the issue.