Sql connection string issue

Solarion

Honorary Master
Joined
Nov 14, 2012
Messages
28,050
Reaction score
17,804
I'm getting this strange error all of a sudden. It's the same across all my previously developed applications.

My connection string reads as such

Code:
  <connectionStrings>
    <add name="dbContext" connectionString="Data Source=DESKTOP-OBLIVION;Initial Catalog=StockTracker;Integrated Security=True;User ID=sa;Password=Qwerty12" providerName="System.Data.SqlClient"/>
  </connectionStrings>

However any connections I try and open to the DB crash because the local account that I log in with keeps getting appended onto the end database name as such.

Code:
DESKTOP-OBLIVION\\MyHomeMachine

I've never seen this before. Perhaps some kind of update did this? It is somehow tying my SQL in with my local account I think. No idea. Any thoughts?
 
I'm getting this strange error all of a sudden. It's the same across all my previously developed applications.

My connection string reads as such

Code:
  <connectionStrings>
    <add name="dbContext" connectionString="Data Source=DESKTOP-OBLIVION;Initial Catalog=StockTracker;Integrated Security=True;User ID=sa;Password=Qwerty12" providerName="System.Data.SqlClient"/>
  </connectionStrings>

However any connections I try and open to the DB crash because the local account that I log in with keeps getting appended onto the end database name as such.

Code:
DESKTOP-OBLIVION\\MyHomeMachine

I've never seen this before. Perhaps some kind of update did this? It is somehow tying my SQL in with my local account I think. No idea. Any thoughts?

DESKTOP-OBLIVION is the server(machine name), MyHomeMachine is the server instance - you need to connect to it if it exists. The actual database is StockTracer.

Edit your connection string to:

<connectionStrings>
<add name="dbContext" connectionString="Data Source=DESKTOP-OBLIVION\MyHomeMachine;Initial Catalog=StockTracker;Integrated Security=True;User ID=sa;Password=Qwerty12" providerName="System.Data.SqlClient"/>
</connectionStrings>

EDIT: I read too fast and misunderstood. Ignore the above. If you never had an instance before, that is odd that it adds it without you adding it in the config.
 
Last edited:
Think I'm just going to re-install SQL Server. Just a really odd thing to start having and all my C# apps are crashing because of it. Weirdness galore!
 
Just do a quick test for me please. Since you already have integrated security checked, can you remove "User ID" and "Password".


<connectionStrings>
<add name="dbContext" connectionString="Data Source=DESKTOP-OBLIVION\MyHomeMachine;Initial Catalog=StockTracker;Integrated Security=True providerName="System.Data.SqlClient"/>
</connectionStrings>
 
Last edited:
So DESKTOP-OBLIVION\ is your computer name, and previously you were connecting to a default instance of SQL Server. Quite an old version yes? Did you just install a new version? The old instance is gone, so you either upgraded the old server, or deleted it and installed a completely fresh new one?

I don't think your new SQL instance is really called MyHomeMachine? I'm guessing it's called SQLEXpress? If you're connecting from the same machine, you don't need DESKTOP-OBLIVION\ either, you only need that if you're connecting from another machine on the same LAN.

Open up computer management, expand services and applications, expand SQL server configuration manager, click on SQL server services, and look what shows in brackets after 'SQL Server'. Here my server is called SQL2016.

1543915214296.png
 
I think the issue started when I re-imaged my drive. This rolled back my version of visual studio and SQL Server to 2014. Somewhere along the line between my local account and SQL something has like unsynched? I'll try this when I get back this afternoon Potty thanks!
 
There were some changes to the security model in dotnet and SQL recently due to "vulnerabilities"
 
I think the issue started when I re-imaged my drive. This rolled back my version of visual studio and SQL Server to 2014. Somewhere along the line between my local account and SQL something has like unsynched? I'll try this when I get back this afternoon Potty thanks!
That makes sense.

in your logs it will tell you what user it is using. Give that user the right access. Integrated security means you are logging in with the user that is running the process.

Also read this :

https://stackoverflow.com/questions...tegrated-security-true-and-integrated-securit

you should be using
Code:
Integrated secuirty=sspi
 
SSPI used to matter back in the days of OleDb, but the OP is using native client.

Setting Integrated security to either SSPI or True will make your app attempt to log into SQL server using windows authentication, even if you include an SQL authentication username and password in your string. If you don't set Integrated security, or set it to false, it will attempt to log into SQL server using SQL authentication, it will then require the username and password.
 
If this was a production environment rollback I'd be in a real jam. Probably better that I learn about this type of issue now. The only hang up atm is that I'm unable to load any of my projects at home but at least it's not an emergency. Will sit down with this in a bit this evening after dinner.
 
I am not sure I am junior but isn't integrated security windows login and you cannot use it with a username and password combination because it will just try login with your windows account?
 
So DESKTOP-OBLIVION\ is your computer name, and previously you were connecting to a default instance of SQL Server. Quite an old version yes? Did you just install a new version? The old instance is gone, so you either upgraded the old server, or deleted it and installed a completely fresh new one?

I don't think your new SQL instance is really called MyHomeMachine? I'm guessing it's called SQLEXpress? If you're connecting from the same machine, you don't need DESKTOP-OBLIVION\ either, you only need that if you're connecting from another machine on the same LAN.

Open up computer management, expand services and applications, expand SQL server configuration manager, click on SQL server services, and look what shows in brackets after 'SQL Server'. Here my server is called SQL2016.

View attachment 587088

I actually don't even have it running under Services and Applications. Going to do a full SQL re-install tired of fighting with it. Tried everything in this thread to no avail. Thinking Microshaft did some update and it messed with all the policies or something.

Edit: Crapsticks! When I refreshed the machine I had previously imaged, I had two accounts on there. One was my admin account the other one I created for a Dev environment. When I first logged in after the refresh I signed into the wrong account. I signed out and signed into the admin account, everything working perfectly :D
 
Last edited:
iWKad22_d.jpg
 
I actually don't even have it running under Services and Applications. Going to do a full SQL re-install tired of fighting with it. Tried everything in this thread to no avail. Thinking Microshaft did some update and it messed with all the policies or something.

Edit: Crapsticks! When I refreshed the machine I had previously imaged, I had two accounts on there. One was my admin account the other one I created for a Dev environment. When I first logged in after the refresh I signed into the wrong account. I signed out and signed into the admin account, everything working perfectly :D


Release the Kraken!

On a serious note, it is always better to figure out that it was a user error and not just some ungodly windows bug. I find windows sqlserver users to be the real brave soldiers of the software industry. Would not be caught dead using sqlserver. :)
 
On a serious note, it is always better to figure out that it was a user error and not just some ungodly windows bug. I find windows sqlserver users to be the real brave soldiers of the software industry. Would not be caught dead using sqlserver. :)

What in your opinion makes it so bad?
 
Top
Sign up to the MyBroadband newsletter
X