简体   繁体   中英

Weird SQL Connection Issue

I've got two applications, one is a pretty standard ASP.NET MVC C# 4.5 and the other is a standard C# 4.5 Windows Application.

They both connect to the same SQL Server using exactly the same connection string, and the web application connects successfully.

However, the Windows Application fails with the following:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The specified data could not be decrypted.\\r\\n)"

This occurs locally, on the test server and the live server but I have absolutely no idea why.

All it's doing using a simple SqlConnection object and calling the Open() method.

I've got another client with the same mix of Web App and Windows App projects and there are no issues like this at all, yet if I copy one of the Windows Apps from the working client and incorporate it into this one, it fails.

I am literally clueless with this one and I think I'm about to cry, so please, if you can offer any insight at all, please do...it's probably something really simple that I'm missing.

2 connection string settings in app.config that I've tried:

<add name="XXXXXX" 
     connectionString="Data Source=.\SQL2014;Initial Catalog=****;User ID=****;Password=****;Persist Security Info=True;MultipleActiveResultSets=True;enlist=false" 
     providerName="System.Data.SqlClient" />

<add name="XXXXXX"
     connectionString="Server=.\SQL2014;Database=****;User ID=****;Password=****;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;MultipleActiveResultSets=true" />

Can't connect to SQL Server database from Local IIS over HTTPS

I think this is due to a component called NCrypt (available via NuGet) which I've isolated to be the cause.

When it's in my bin folder the executable fails to connect to SQL, and when I delete it the connection succeeds like I would expect.

The chances of anyone else giving me the answer to this were minimal at best, so I'm sorry to have wasted your time...

At least I've worked it out!

Try adding Integrated Security=true; to your web config. You can also specify Trusted_Connection=True; or Integrated Security=SSPI; All of these mean the same. I suspect your Windows Authentication is not trusted on the desktop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM