Delphi 7 failing to pickup username and password from UDL - sql-server

I'm having issues trying to get Delphi 7 to connect to a remote MSSQL server.
This is the extent of the code:
UDLPath := 'FILE NAME=C:\Path\To\UDL.UDL';
TestConnection := TADOConnection.Create(nil);
with TestConnection do
begin
ConnectionString := UDLPath;
try
Connected := True;
except
ShowMessage('Failed');
end;
end;
I get the error "Login failed for user ''. The user is not associated with a trusted SQL Server connection"
I have LoginPrompt set to false in the IDE. I tried setting it to true, but it's hitting the except before it prompts for a login.
The test connection button works in the UDL, and I can connect to the server through SSMS.
I've tried using a raw connection string with the userid and password fields set properly, but that didn't work.

maybe this could help you, see the two links:
https://support.microsoft.com/en-us/kb/889615
http://blog.sqlauthority.com/2014/01/17/sql-server-fix-login-failed-for-user-username-the-user-is-not-associated-with-a-trusted-sql-server-connection-microsoft-sql-server-error-18452/

The issue was with the provider. The native client 10 driver was failing to authenticate for an unknown reason, but the ODBC for SQL driver worked fine.

Related

Getting The login is from an untrusted domain and cannot be used with Integrated authentication

I have a windows authentication user created on SQL server. I am trying to connect SQL server using that user, but I am getting java.sql.SQLException: The login is from an untrusted domain and cannot be used with Integrated authentication. error.
I am using jtds-1.3.jar. My connection url is jdbc:jtds:sqlserver://xyz.net:1433;instance=dev;databaseName=XYZ;integratedSecurity=true;useNTLMv2=true;domain=XYZ.net
I have checked the connection and traffic is allowed between my client machine and server. I tried setting intgratedSecurity= false as suggested in other answers but that did not work.
What properties of user should I check to know that user is correctly configured on SQL sever for JDBC connectivity?
Finally, got this connection working. It turns out the best way to connect to SQL server using jTDS driver is to create SQL server user avoid creating windows user. And stick to SQL server based user.
The message The login is from an untrusted domain and cannot be used with Integrated authentication can be misleading. For example you can get it by entering the right username with the wrong password.
Without knowing the exact configuration of your SQL server is difficult to say but I would try with a simpler connection string:
jdbc:jtds:sqlserver://xyz.net:1433;databaseName=XYZ
I don't use jTDS directly but the version embedded inside Aqua Data Studio and we don't use named instances but, anyway, I provide the configuration I use with freeTDS in a Linux box as an example of a simple configuration that works perfectly against an cluster instance of SQL Server 2014.
In /etc/freetds/freetds.conf:
[conn1]
host = host.dom.ain
port = 1433
tds version = 7.4
Query from the command line using tsql:
/usr/bin/tsql -S conn1 -U DOMAIN\\USER << SQL_DATA
SELECT getdate();
GO
QUIT
SQL_DATA
Password:
locale is "es_ES.utf8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> 2>
11-11-2022 01:26
(1 row affected)

Unable to connect to remote SQLServer using 'sa'

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.

SqlServer: Login failed for user

I've written a very simple JDBC login test program. And after all kinds of problems I've almost got it working. Almost, just can't seem to get past this problem:
SQLServerException: Login failed for user xxxxx
I created a simple database PersonInfo then I created user user1 password1 (SQL authentication). And after trying everything was unable to connect to the database.
I am using SqlServer2008 on Win 7, I've got the latest JDBC driver from Microsoft.
My code is:
import java.sql.*;
public class hell {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn= DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=PersonInfo;user=Sohaib;password=0000;");
System.out.println("connected");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here's the Exception
Exception: Unable to get connect
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'Sohaib'.
and all other supporting errors.
Is your SQL Server in 'mixed mode authentication' ? This is necessary to login with a SQL server account instead of a Windows login.
You can verify this by checking the properties of the server and then SECURITY, it should be in 'SQL Server and Windows Authentication Mode'
This problem occurs if the user tries to log in with credentials that cannot be validated. This problem can occur in the following scenarios:
Scenario 1: The login may be a SQL Server login but the server only accepts Windows Authentication.
Scenario 2: You are trying to connect by using SQL Server Authentication but the login used does not exist on SQL Server.
Scenario 3: The login may use Windows Authentication but the login is an unrecognized Windows principal. An unrecognized Windows principal means that Windows can't verify the login. This might be because the Windows login is from an untrusted domain.
It's also possible the user put in incorrect information.
http://support.microsoft.com/kb/555332
In my case, I had to activate the option "SQL Server and Windows Authentication mode", follow all steps below:
1 - Right-click on your server
2 - Go to option Security
3 - Check the option "SQL Server and Windows Authentication mode"
4 - Click on the Ok button
5 - Restart your SQL Express Service ("Windows Key" on the keyboard and write "Services", and then Enter key)
After that, I could log in with user and password
I ran into the same issue, and I fixed it by adding my windows username to SQL and then to my server, here is how I did:
First, create a new login with your Windows username:
Click Search, then type your name in the box and click check names.
Then add your that user to the server:
Right click on the Server > Permissions > Search > Browse > Select your user
(You will notice that now the user you created is available in the list)
I hope it helps ;-)
We got this error when reusing the ConnectionString from EntityFramework connection. We have Username and Password in the connection string but didn't specify
"Persist Security Info=True".
Thus, the credentials were removed from the connection string after establishing the connection (so we reused an incomplete connection string). Of course, we always have to think twice when using this setting, but in this particular case, it was ok.
I got the same error message when trying to connect to my SQL DB in Azure (using sql-cli). The simple solution was to escape the password with single quotes like this:
mssql -s server.database.windows.net -u user#server -p 'your_password' -d your_db -e
Also make sure that account is not locked out in user properties "Status" tab
For Can not connect to the SQL Server. The original error is: Login failed for user 'username'. error, port requirements on MSSQL server side need to be fulfilled.
There are other ports beyond default port 1433 needed to be configured on Windows Firewall.
https://stackoverflow.com/a/25147251/1608670
We solved our Linux/php hook to SQL Server problem by creating a new login account with SQL Server authentication instead of Windows authentication.
Just in case any one else is using creating test users with their automation....
We had this same error and it was because we had recreated the user (as part of the test process). This caused the underlying SID to change which meant that SQL couldn't properly authenticate the user.
We fixed it by adding a drop login command to our testing scripts to ensure that a previously created user (with the same user name) was no longer present on the instance.
I faced with same problem. I've used Entity Framework and thought that DB will be created automatically. Please make sure your DB exists and has a correct name.
In my case I have configured as below in my springboot application.properties file then I am able to connect to the sqlserver database using service account:
url=jdbc:sqlserver://SERVER_NAME:PORT_NUMBER;databaseName=DATABASE_NAME;sendStringParametersAsUnicode=false;multiSubnetFailover=true;integratedSecurity=true
jdbcUrl=${url}
username=YourDomain\\$SERVICE-ACCOUNT-USER-NAME
password=
hikari.connection-timeout=60000
hikari.maximum-pool-size=5
driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
try using this connection string
Server=ServerName;Database=DbName;Trusted_Connection=SSPI;MultipleActiveResultSets=true;TrustServerCertificate=true
If you are using Windows Authentication, make sure to log-in to Windows at least once with that user.
Previously I was using the Windows Authentication without problems, then occurred me the error below.
"Failed to generate SSPI context."
Witch I resolve by changing my connection string from
Server=127.0.0.1;Database=[DB_NAME];Trusted_Connection=True;
to
Server=127.0.0.1;Database=[DB_NAME];Trusted_Connection=False;
Then the next error occurred me
"Login failed for user ''."
To solve this problem I used the sa user. Access the sa user to update de password if you need (on the SQL server Security > Logins > sa (right click) > Properties > General)) and then update the connection string to..
Server=127.0.0.1;Database=[DB_NAME];User Id=sa;Password=[YOUR_PASSWORD]
You can use another user of your choice.

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

Cannot Connect to SQL Server Express 2014 from java

I've been at this for a few days now and the error stays the same.
Login failed for user". ClientConnectionId
I have connected to the database successfully, but the "login failed for user" which doesn't make sense because the username is "sa" and the password "tazmo1", the same as the login and password was when installed SQL Server Express. This is what i have so far...
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String userName = "sa";
String password = "tazmo1";
String url = "jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2012;integratedSecurity=true";
con = DriverManager.getConnection(url,userName,password);
I have also used
con = DriverManager.getConnection(url)
and
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2012;integratedSecurity=true")
even used
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks2012,user="sa",password="tazmo1");`
I've been reading numerous stackoverflow forums that point me to the same thing, make sure the TCP/IP dynamic ports are removed add 1433 to all the TCP/IP Port. I have done all that, and it connect then stops working as the "login failed". Please help me fix this issue.
You have IntegratedSecurity set to true. That will use your Windows Auth credentials, even if you are passing in the SQL Auth credentials.
The problem is: you are using integratedSecurity=True which means you are using microsoft's standard instead of yours, set it to false and it will use YOUR username and password. You could also try this, instead of integratedsecurity: "databaseName=AdventureWorks;user=MyUserName;password=*****;";

Resources