SQL Server connection failure - sql-server

I have a library that handles connections to my database. It has a connection string that includes the credentials needed to login to the database. I am referencing that library with several apps. It works in all but one. It used to work for that one but stopped with the most recent library build. It comes back with a Connection refused for user XXX. The SSMS logs record it as a password mismatch Error: 18456, Severity: 14, State 8.
I've provided the connection string just in case you want to see, but I think it must be something trickier than a connectionstring typo, since it's working elsewhere.
<connectionStrings>
<add name="POIRepository.Properties.Settings.MoMConnectionString"
connectionString="Data Source=server;Initial Catalog=database;Persist Security Info=True;User ID=user;Password=password"
providerName="System.Data.SqlClient" />
</connectionStrings>
I can login directly into SSMS using the same credentials as well. I don't really see how this is possible. Does anyone have any ideas of things to try?

Related

How to fix "Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net)"

I have a web application in visual studio 2017 .NET framework 4.7.1 with identity, that connects to azure sql server database. I am getting an error after submitting login form. The exception message is:
"Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net). Some libraries do not send the server name, in which case the server name must be included as part of the user name (username#servername). In addition, if both formats are used, the server names must match."
The error is only in the web server (azure app service). When I run it locally (localhost) it works fine.
I did what error message suggests but, it did´nt work. I searched about this but, none of the suggestions or solutions I found have worked.
If I remove login stuff, application is able to connect and works so, the problem seems to be the connection string I use to connect to identity tables.
I have tried this connection strings in web.config but none of them have worked:
1.
add name="DefaultConnection" connectionString="Server=tcp:myServer.database.windows.net,1433;Initial Catalog=myDatabase;Persist Security Info=False;User ID=myUser#myServer;Password=myPassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False" providerName="System.Data.SqlClient"
2.
add name="DefaultConnection" connectionString="Data Source=myServer.database.windows.net;Initial Catalog=myDatabase;Integrated Security=False;User Id=myUser;Password=myPassword;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"
First, did you set the Allow access to Azrue Service ON?
Please check your Azrue SQL Database firewall settings on portal:
Second, get the correct connection string:
Others, please see: Troubleshooting connectivity issues with Microsoft Azure SQL Database.
Hope this can helps.

CREATE DATABASE permission denied in database 'master' when Integrated Security=false - Why try to create a database that already exists?

I have an ASP.net MVC app connecting to (localdb)\v11.0 SQL Server database with a connection string using "Integrated Security" - works fine.
Now I want to connect to the same db with a User ID & PW.
I created the login & user: user100, gave it db_owner permission.
I can open the db with that ID/PW using SSMS.
But when I change my connection string to "User ID=user100 & Password=xxxx", I get the error:
CREATE DATABASE permission denied in database 'master'.\r\nCannot
attach the file
'C:\Projects\ExcellerWeb\ExcellerWeb\App_Data\ExcellerWebCopy.mdf'
as database 'ExcellerWebCopy'.
Why does it try to create a database that already exists?
And the following code returns TRUE:
System.Data.Entity.Database.Exists("UserConnection");
At first I thought it was EF Migrations, but it seems to happen on a simple test project without Migrations.
Here's my connection string:
<add name="UserConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\ExcellerWeb.mdf;Initial Catalog=ExcellerWeb;Integrated Security=False;User ID=user200; Password=****"
providerName="System.Data.SqlClient" />
Remove the Option AttachDbFilename from your connectionstring.
<add name="UserConnection"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ExcellerWeb;Integrated Security=False;User ID=user200; Password=****"
providerName="System.Data.SqlClient" />
This option is there to attach the file when you open the connection.
For more details have a look at this or this MSDN-article
This isn't an answer to the original question, but we got the same error message when we moved a web app and database to new hardware, and a Google search led me here, so hopefully this might help someone...
In our case, the connection string that the web app used was fine, and the database already existed, so the error message was a bit of a surprise.
The problem turned out to be that the service account running the app pool in IIS didn't have the correct permissions on the database - when the account was added to the appropriate group, everything worked fine.

azure sql server database connection errors

I am pretty new to all the azure thing, till now my project was connected to localhost database.
i managed to create server in azure and uploaded my database to that server, i opened the access for my IP and everything was fine till i tried to use my website with functions that use the database (Sign up).
First, i got an error from the browser says:
Login failed for user '{user}'. so i added the server name to the user name like user#server_name. that solved this error.
After this i tried again and another error came up from the browser Cannot open server "server_name}" requested by the login. The login failed.
I have no idea why the login is failing... when i try to log in to the data base from SSMS i have no problems, i have put the same credentials for login in the connectionString web.config file, so i have no idea what the problem is.
Here is my connectionString:
<connectionStrings>
<add name="myapp"
connectionString="Server=tcp:myapp.database.windows.net,1433;Data Source=myapp.database.windows.net;Initial Catalog=myapp;Persist Security Info=False;User ID={XXXX};Password={XXXXXX};Pooling=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Please help.
Try this one instead.
Server=tcp:[serverName].database.windows.net;Database=myDataBase; User
ID=[LoginForDb]#[serverName];Password=myPassword;Trusted_Connection=False;
Encrypt=True;
That solved my problem:
<connectionStrings>
<add name="DB_Name"
connectionString="Server=server_name,1433;Database=DB_Name;User ID=user_name;Password=user_password"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Now everything work locally and from the server too

Deploying code first code migrations based web app to server, but it's not creating the database

I have my own box so I have complete control over the server. I'm using SQL server 2008. I run the application hoping it will create the database, but I keep getting the error:
Cannot open database "blah blah" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\appname'.
I've tried to go into SSMS and add the user IISAPPPOOL\appname but that hasn't helped any. Here's the connection string from my web.config
<add name="Context"
connectionString="Data Source=Server\DbInstance;Initial Catalog=blahblah;Integrated Security=True;User ID=myUser;Password=myPassword"
providerName="System.Data.SqlClient" />
and the initializer from my global.asax
Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>());
Is the app failing because code first is failing and not creating the database or is it because of permissions issues? If I need to provide more specific information I can.
Well, one problem you have: you're defining both Integrated Security=True (i.e. Windows authentication) as well as User ID=...;Password=.... (i.e. SQL Server authentication) in your connection string.
Choose one or the other - but not both at the same time!
If you do have that user myUser specified as a login in your SQL Server, right now, it will not be used, because the Integrated Security=True setting will prevail ...
So change your connection string to:
<add name="Context"
connectionString="Data Source=Server\DbInstance;Initial Catalog=blahblah;User ID=myUser;Password=myPassword"
providerName="System.Data.SqlClient" />
and see if now, you're myUser user will be used.

EntityFrame work connection string issue

I am working on a Silverlight application. during development I have been working with a copy of our production database on my local machine.
When setting up the project I created a model of the local database, and then created a domain service of that model to interact with the data. This is all working well. Now I need to test my product against the live server, but I can not seem to figure out the connection string.
Currently the connection string looks like this.
<add name="UserDataEntities" connectionString="metadata=res://*/Models.UserDataModel.csdl|res://*/Models.UserDataModel.ssdl|res://*/Models.UserDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=RTRP20112_NATP_UserData;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
The only differance between the database I have been using locally, and the production database is its location. I have attempted to simple replace the data source portion of the connection string with the correct address, and login info but that does not work. I have also duplicated the connection string used by another application to connect to this database, but that does not work since it is missing all the metadata junk(i think). I am not sure how to proceed.
The connection string used by other programs to connect to the server is
<add name="UserDatabase" connectionString="Data Source=*.*.*.*,*;Network Library=DBMSSOCN;Initial Catalog=RTRP20112_NATP_UserData;User ID=*;Password=*;" providerName="System.Data.SqlClient"/>
I have tried a few variations of the two as a connection string, most recently I am using.
<add name="UserDataEntities" connectionString="metadata=res://*/Models.UserDataModel.csdl|res://*/Models.UserDataModel.ssdl|res://*/Models.UserDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=*.*.*.*,*;Network Library=DBMSSOCN;Initial Catalog=RTRP20112_NATP_UserData;User ID=*;Password=*;App=EntityFramework"" providerName="System.Data.EntityClient" />
The most recent error is: Load Error
System.ServiceModel.DomainServices.Client.DomainOperationException:Load operation failed for query 'GetUsers'. The undelying provider failed on Open.
Have you configured/created ASPNETDB ?

Resources