Unable to connect to remote SQLServer using 'sa' - sql-server

I'm trying to connect to a remote instance of SQLServer using a connection string for a Go program that I'm writing.
I have a local version of the remote database with the same users.
If I connect to my local DB with a connection string like this, it works just fine:
Data Source=localhost;Initial Catalog=master;User Id=<user>;Password=<password>;
Now if I use the same credentials, but I just change the data source, it also works just fine:
Data Source=<remoteIP>;Initial Catalog=master;User Id=<user>;Password=<password>;
Now if I try and log in using 'sa', it works locally, but not remotely.
This works just fine:
Data Source=localhost;Initial Catalog=master;User Id=sa;Password=<password>;
But this does not work:
Data Source=<remoteIP>;Initial Catalog=master;User Id=sa;Password=<password>;
The error I get when I try to connect to the remote server in my Go program is:
Login error: mssql: Login failed for user 'sa'.
The really frustrating part is that if I copy and paste the username and password, I can connect to the remote DB in SMSS using that login information, and everything works just fine.
I've double-checked to ensure that the remote 'sa' login allows for both Windows Authentication and SQL Authentication. Is there another setting or something that would prevent me from being able to log in to my remote server using 'sa'?
I'm so puzzled because I clearly can connect to the remote DB if I'm using a different user, but I can't connect using 'sa'.
Are there additional settings I have to configure on the remote server? I'm also a bit frustrated with this because I can't print out what the actual error code is. It just tells me that my login failed when I print the error message.

I figured out my problem.
For the new user that I created (see the original post's comments), it couldn't connect because of my connection string.
I tried first making my connection string the following, which still worked connecting me locally:
Initial Catalog=master;User Id=<user>;Password=<password>;
I was confused because this still worked, despite me not setting a Data Source.
So what I did was try using "Server", and it worked:
Server=<remoteIP>;Initial Catalog=master;User Id=<user>;Password=<password>;
So it turns out it was an invalid credential error because it was always trying to connect to my local DB. Thanks for everyone's input.

Related

Not able to login via specified user in localhost SQL Server connection string

I am new to SQL Server and I am trying to connect a localhost SQL Server. And I am having the following exception:
Cannot open database "MyDatabase" requested by the login. The Login failed Login failed for user "MyCodingPC\Cyborg".
And also I don't understand why it is getting logged in via that username when I have specified another user in the connection string.
My connection string
Data Source=xxx.xxx.xx.xxx,1433\(localdb)\MSSQLLocalDB;Network Library=DBMSSOCN;Initial Catalog=MyDatabase;User Id=MyNewUser;Password=pass##$word;Integrated Security=True
LocalDB cannot be used over TCP. So to accomplish my requirements I used SQLExpress instead.
LocalDB is supposed to work only for local access; remote access is not possible here.

Can connect and access SQL Server database using SSMS and VS, but login fails in report code

SQL Server login error being thrown when attempting to export DevExpress report, even though the same connection string is working fine elsewhere in code and other applications.
Error is as follows:
System.Data.SqlClient.SqlException: Login failed for user 'USERNAME REMOVED'.
All code is referring to a single connection string in the web.config file.
I can remotely login and access the desired database in SSMS and VS's Server Explorer using the same login details. I have double checked the details being used are the same.
When I try to set up the connection for the report through VS's connection editor wizard, I am getting the same error.
As far as I can tell this issue was due to special characters in the user's password, it appears that some applications were handling these characters and successfully logging into SQL Server under that username, while others could not.
Updating the user's password resolved the issue.

Connecting to SQL from Bamboo still throws error Login failed for user

I am attempting to connect my Bamboo instance to SQL Server, but I am unable to do so because of the error Login failed for user 'Bamboo'. Investigation into the log files shown in the location
C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log\ERRORLOG
throws an error that I should not be getting at this stage of my attempted login. Server is configured for Windows authentication only. Currently able to login using same SQL Server credentials to access the database, just not via Bamboo.
The reason why this should not happen is because my server is already set up to do so, and I will list all of the steps that I have taken to prevent this error. In my localhost SQLEXPRESS server I have checked SQL Server and Windows Authentication mode. Once I restarted SQL Server, this worked as I was able to log in with the credentials that I added to a user called Bamboo.
The user I added is mapped to the database called BambooDatabase as a db_owner. The number of concurrent users is unlimited and I have tried disconnecting from SQL Server just to check if that was a problem, but still no difference. I added 2 more users with connect access and mapped to BambooDatabase.
I have went to the SQL Sever Configuration Manager and enabled TCP/IP and made sure that the IP addresses was pointing to 1433. And then configured my firewall to all access to 1433 as well. The fact that my error logs for SQL Server are appearing makes this seem that everything should be fine here. So with tested 3 users on SQL credentials everyone logged in successfully and all have the relevant permissions needed. All three gave the same error when trying to connect from Bamboo.
I am trying to connect to Bamboo like this:
Direct JDBC connection.
Driver class name: net.source.jtds.jdbc.Driver
Database URL: jdbc:jtds:sqlserver://localhost:1433;DatabaseName=BambooDatabase
User name: Bamboo
Password: SQL Server password
Checked overwrite existing data
Then once I click continue the log in error throws. Have I missed something here, I cannot see what I could do differently, I have tried to connect to SQL Server from Bamboo several different ways but have had no success. I am using SQL Server Express and the Bamboo version 5.11.3, I am testing upgrading from 5.11.3 to 5.15 with larges amounts of data which is why I am using that version.
Error from Bamboo is:
Error accessing database: java.sql.SQLException: Login failed for user 'Bamboo'.
Error from SQL logs is:
Login failed for user 'Bamboo' Reason: An attempt to login using SQL authentication failed. Server is configured for Windows authentication only. [CLIENT: 127.0.0.1]
Are you running Bamboo en SQLExpress on the same machine? If not, you should look into the remote access configuration.
In the SQL Sever Configuration Manager, make sure that you entered 1433 for the IPAll entry as well. And start the SQL Browser service for good measure, this is especially important when using a names instance, but going after the errorlog folder you copy/pasted, that's not the case.
For testing purposes, you might want to disable the firewall all together and reactivate is after you get the connection up.
Another thing to try if you're connecting on the same machine, is use the loopback address 127.0.0.1 instead of the localhost alias.

SQL Server login works in a connection string, but fails in DSN

I have a web site and I'm trying to setup a DSN instead of using a connection string because it seems more secure.
The following connection string works fine in my site:
"Server=servername; database=mydb; user id= web.account; password=PassW0rd!; Integrated Security=SSPI"
However, when I try to set up a DSN (using the 64-bit odbc admin) I get the following error:
Connection failed:
SQLState: '28000'
SQL Server Error: 18456
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'web.account'
Keep in mind, I'm using the same account and password I use in the connection string (which works). It's weird too because the error occurs right after I click 'Next' on the "How should SQL Server verify the authenticity of the login ID?" page.
It seems like the odbc admin does not even try to connect to the server to verify the credentials. What can I check to prove this / How can I fix this?
Things I've tried:
I have checked the server authentication mode, as proposed in other solutions, and that is set to "SQL Server and Windows Authentication mode", as it should be.
I have tried creating both a User and System DSN - both get the same error, this seems like further evidence that it's not trying to connect to the server to check the credentials.
I have tried the same DSN creation on multiple servers, all have the same problem. Is it possible the SQL Server is refusing these types of connections?
UPDATE 1:
The DBA just told me that the web.account is actually a Windows account, not an SQL account. I guess that's why the odbc isn't working, because it doesn't try to connect as a different windows user, only as the current windows user. So now the question is, how do I set up a DSN with a different windows account? Or, is that even possible?
This post has a response that says DSNs setup with NT authentication are specifically for the entire system, not a specific account, so a runas command could be used from cmd, like so:
runas /netonly /user:domain\web.account "C:\Windows\SysWOW64\odbcad.exe"
It will then ask you for the web.account password. Then you can create a DSN, and this should work.
UPDATE: I had to add the web.account user to my Administration Group using this fine how-to. Then I had to run cmd as my elevated account. Then ran the runas command I showed above. Then, I was finally able to create a non-native DSN, which allowed me to connect to the Data Server as a different Windows user.
Still waiting for DBA to check the logs to say this actually worked or not, but I feel pretty good about it. Will update after confirmation.
Try the following:
Data Source=servername;Initial Catalog=mydn;Persist Security Info=True;User ID=web.account;Password=Passw0rd
This is what I use to connect.

Excel VBA connect to SQL Server Login Error

I am a beginner in Excel VBA and faced a problem: I can connect to remote SQL Server through Management Studio, but got error when connecting through Excel VBA.
Below is my connection string and the error code.
Const connection_string As String = "Provider=SQLOLEDB.1;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=RPGTFDB;Data Source=122.xxx.xxx.xxx;User ID=sa;Password=xxx"
Error is:
Run-time error (80004005): Login failed for user ". The user is not associated with a trusted SQL Server connection.
Is it not able to get the User ID?
However when I connect to local computer, like 127.0.0.1, the above connection string works.
Thanks a lot!
In your connection string you should not use
User ID=sa;Password=xxx
As the error seems to be indicating that only Windows Logins are enabled on the SQL Server and this connection string item is only for SQL Logins.
Do you have to punch in a login and password when connecting with management studio? If not then I suggest you have a database that authenticates a connection using your windows login.
If this is the case, then remove the User ID and Password bits and insert Trusted_Connection=Yes instead.
Finally, the connection string is created using UDL application.
Despite I still cannot find any difference between the string and the manual created one, it works!
Follow the instructions in this link:
http://social.technet.microsoft.com/wiki/contents/articles/1409.how-to-create-a-sql-connection-string-for-an-application-udl-file.aspx

Resources