145

I am having error while connecting to SQL Server:

enter image description here

Details in Stack Trace are:

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

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()

NOTE I have tried

  • closing, reopening Sql server Management Studio.

  • closing , reopen VS & rebuild Solution

  • killed worker process accessing database.

  • login credentials are correct.

  • able to ping server to make sure its not down.

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
  • 2
    Possible duplicate of [SQL Server 2008 Error 233](http://stackoverflow.com/questions/6072505/sql-server-2008-error-233) – MusicLovingIndianGirl Dec 23 '15 at 07:19
  • 6
    Check whether all your SQL Services are running. If yes, still restart all once and check again. Also, check whether MIxed authentication mode enabled for your SQL server. – Paresh J Dec 23 '15 at 07:21
  • 1
    I have enabled and started the browser service and the issue resolved. Please try. – user6232480 May 30 '17 at 17:49
  • My server is running in Mixed mode, I've stopped and started it and I'm still getting this error :-(. I'm getting this from SQL localdb specifically. – bytedev Aug 10 '18 at 09:52
  • same problem happened to me and changing the DNS to the google DNS (8.8.8.8) fixed it – Hossein Narimani Rad Mar 28 '23 at 06:51

33 Answers33

169

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"

NOTE: This certificate configuration is not recommended for production environments.

Tyson Gibby
  • 2,590
  • 2
  • 18
  • 37
109

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.

user7643068
  • 1,099
  • 2
  • 7
  • 2
33

This is what helped me [src]:

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

enter image description here

Duck Ling
  • 1,577
  • 13
  • 20
31

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;"
Rauland
  • 2,944
  • 5
  • 34
  • 44
  • 6
    +1 This seems to be the new norm for .Net Core 7. Was working fine yesterday before updating, but today failed until this was added. – EvilDr Nov 11 '22 at 14:01
  • 5
    It works fine but I think it's a better idea to add TrustServerCertificate=True instead of disabling encryption by adding Encrypt=False. – Sinan ILYAS Nov 15 '22 at 13:18
  • 1
    down voted because disabling encryption may be against many companies policies, and at the least is against best practice. – Andrew Hill Jan 02 '23 at 23:22
29

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

Ruli
  • 2,592
  • 12
  • 30
  • 40
Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
  • Use Sql Server Configuration Manager > SQL Server Services to find out what processes are running (C:\Windows\SysWOW64\SQLServerManager15.msc) – Denis G. Labrecque Apr 19 '22 at 15:45
27

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

Vojtěch Vorel
  • 371
  • 3
  • 4
23

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

Joseph Wu
  • 4,786
  • 1
  • 21
  • 19
7

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!

Rikalous
  • 4,514
  • 1
  • 40
  • 52
4

For MS SQL Management Studio

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

Edit:
For Those wondering how to reach the above window. The options button could be found in the bottom right corner of the login dialogue Screen shot of login dialogue

Community
  • 1
  • 1
Thabet
  • 307
  • 1
  • 3
  • 10
3

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
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • 1
    Correct me if I am wrong but if you cannot login Object Explorer will not show the instance of the server – Bmize729 Jun 28 '18 at 01:31
  • I'm having trouble starting SQL Server Agent to try that. It wont' start for me.' – Sam Oct 02 '20 at 23:32
  • This was my issue (Azure Sql Server). I was processing a queue with hundreds of messages all arriving at once. Resolved by slowing the queue down to process 5 at a time. – GreenRock Nov 23 '22 at 23:35
3

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

enter image description here

Kishor K
  • 1,435
  • 12
  • 16
3

I solved it using this parametres Trusted_Connection=true;TrustServerCertificate=True

If you have a problem, update OLEDB Driver 18.6.5

Thanks.

aemre
  • 2,351
  • 2
  • 17
  • 20
2

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.

1

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.

Tawab Wakil
  • 1,737
  • 18
  • 33
1

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

and 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

1

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.

code11
  • 1,986
  • 5
  • 29
  • 37
Adam Lincoln
  • 11
  • 1
  • 2
1

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

lnagy
  • 23
  • 6
1

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
Moiz Tankiwala
  • 6,070
  • 7
  • 38
  • 51
1

Got this error from downloading Microsoft.Data.SqlClient package

removed Microsoft.Data.SqlClient package and it worked.

David Morrow
  • 262
  • 4
  • 9
  • I got it working doing the reverse. By removing System.Data.SqlClient and adding the newer Microsoft.Data.SqlClient. – M.Parent May 04 '23 at 15:29
0

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

Alex
  • 9
  • 4
0

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

Milo
  • 3,365
  • 9
  • 30
  • 44
Viteokntl
  • 21
  • 1
0

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.

Kellen Stuart
  • 7,775
  • 7
  • 59
  • 82
0

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

mouchin777
  • 1,428
  • 1
  • 31
  • 59
0

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.

Pinpaho
  • 187
  • 2
  • 5
  • 15
0

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.

  • If there is an password policy to strengthen password, please change password according to policy and don't disable policy. It will work but will make your application susceptible to hacks & less secure. – Pranav Singh May 04 '21 at 12:17
0

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.

RobLW
  • 66
  • 10
0

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

nightcoder
  • 13,149
  • 16
  • 64
  • 72
0

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.

jmoreno
  • 12,752
  • 4
  • 60
  • 91
0

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.

grey
  • 209
  • 3
  • 6
0

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. :)

shayuna
  • 476
  • 4
  • 8
0

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.

Pieter
  • 69
  • 1
  • 2
0

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.

Tim
  • 4,051
  • 10
  • 36
  • 60
0

SO warns me that I had to review all previous 30+ answers - I did and I am pretty sure my case is different.

My reason was that I was connecting to MSSQL 2019 using password and my password was lost and was specified as Password=; in the .net connection string.

And it really looks like a bug in MSSQL. If I specify any other invalid password the error is "Login failed for user X". And what is really strange is that if I specify blank password again (after specifying non-blank invalid password) the error is "Login failed for user X" again. Not that strange one about "connection established" and so on.

sarh
  • 6,371
  • 4
  • 25
  • 29