I'm trying to connect to my MS-SQL DB with Google Apps Script using the JDBC function.
We use windows integrated security, but when i try to connect with this parameter i get an error saying that it's not supported.
I've already tried to provide my windows credentials and using the param "IntegratedSecurity=true" but can't connect, tried with server IP and Name but doesn't work either.
var address = 'serverIP'; //ex. '10.1.1.1:1433'
var user = ';username=username';
var userPwd = ';password=password';
var db = 'dbname';
var dbUrl = 'jdbc:sqlserver://' + address + ';databaseName=' + db;
function readData() {
var conn = Jdbc.getConnection(dbUrl,user,userPwd);
}
I've tried this form too:
var conn = Jdbc.getConnection("jdbc:sqlserver://MyServerIP:1433;databaseName=DBName;integratedSecurity=true");
It should connect to the server but all I get is errors
The errors are
In the first form:
"Unable to connect to a database. Check the connection string,
username and password. (line 12, file "Code")"
And in the second form:
"The following connection properties are not
supported: integratedSecurity. (line 13, file "Code")"
The instructions for using Windows Integrated Authentication from non-Windows platforms is here: Using Kerberos integrated authentication to connect to SQL Server On Windows you have an additional option using a platform .dll as described here: Connecting with integrated authentication On Windows
I have no idea whether either of these is viable in whatever "Google Apps Script" is.
Related
I have a console application that uses .NET Framework 4.8, and I need it to connect to an Azure SQL database, I have simplified the issue to the following sample:
using(var con = new SqlConnection(myConnectionString)) {
con.Open();
// ...
}
...where the connection string takes the form:
Server=MyDbAddressHere;Initial Catalog=MyDbName;Persist Security Info=False;User ID=MyUsername;Password=MyPassword;MultipleActiveResultSets=False;Encrypt=True;TrueServerCertificate=False;Authentication=Active Directory Password;
I am getting an exception when opening the connection:
AdalException: WSTrust response does not have recognized SAML assertion.
I'm not sure how to interpret the error I'm getting, and how to go about fixing it so I can connect to the database and use it.
Changing the password solved the problem; apparently it had something to do with the account recently having been changed to no longer require MFA.
I'm trying to update my script to use Get-StoredCredential for creating a connection to SQL-Server. Below is what I've tried so far without success:
$creds = Get-StoredCredential -Target dbStoredCredentials
$newConnection = New-Object System.Data.SqlClient.SqlConnection
$newConnection.ConnectionString = "Data Source=my-apps-server;Initial Catalog=myDatabase;"
$newConnection.Credential = $creds
This causes the following error:
Exception setting "Credential": "Cannot convert the "System.Management.Automation.PSCredential" value of type
"System.Management.Automation.PSCredential" to type "System.Data.SqlClient.SqlCredential"."
How can I get the SQL connection to authenticate with StoredCredential?
Using a System.Data.SqlClient.SqlCredential means you're using SQL Server Authentication. It's equivalent to putting the username and password in the connection string.
If you want to use a stored Windows credential, then create a Windows Credential targeting YourSQLServer:port (eg myserver.mydomain.com:1433) and use
Integrated Security=true in your connection string. The driver will access the credential store for you and perform NTLM authentication using the stored credential rather than the identity of the thread opening the connection.
I am having trouble accessing my SQL Server database using Kerberos with a JDBC connection. Note I'm running Linux with Spark version 2.2.0.
I am not specifying anything related to kerberos tickets in my spark_connect, as I've heard rstudio server pro may have an overlapping capability, though I am not sure if it applies to this.
My connection looks like:
table <- sparklyr::spark_read_jdbc(
sc,
"AMI_DATA_STAG_RES",
options = c(list(
url = paste0("jdbc:sqlserver://", <MY SERVER>),
databaseName = "fun_db",
dbtable = "fun_tbl",
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver",
integratedSecurity = "true",
authenticationScheme = "JavaKerberos"))
)
The error I get is:
Error: com.microsoft.sqlserver.jdbc.SQLServerException:
Kerberos Login failed: Integrated authentication failed.
ClientConnectionId:878fa848-91cb-4d78-bd48-6dad88b1e401
due to javax.security.auth.login.LoginException
(Cannot get any of properties: [user, USER] from con properties not available to garner authentication information from the user)
I've read solutions on the internet, but I'm not sure what applies to windows and what will work with my Rstudio Server set-up on Redhat.
Any help appreciated. I'm pretty new to the wonderful world of Kerberos.
EDIT: I've updated my spellings (thanks!) and pasted in the new error. If I add into the connection string my username and password then I think it does work, but I want to avoid having to paste in my password.
Adding in just my username yields the error:
Error: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot login with Kerberos principal dzafar, check your credentials. Kerberos Login failed: Integrated authentication failed. ClientConnectionId:543c9b44-e1e0-4fe8-8510-235a21be2845 due to javax.security.auth.login.LoginException (Cannot get any of properties: [password, PASSWORD] from con properties not available to garner authentication information from the user)
I'm trying to use DriverManager.getConnection() to connect to a SQL Server db from a Java application, but I keep getting "Login failed for user" errors with it. I've tried using both com.microsoft.sqlserver.jdbc.SQLServerDriver and net.sourceforge.jtds.jdbc.Driver to connect, but both keep hitting the issue.
Here's the code I'm using to connect:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:jtds:sqlserver://SERVERADDRESS:1433;DatabaseName=DBNAME;user=USER;password=PASS");
I know that account has access to that DB, as I've connected to it before from a Python application using pymssql.connect(SERVERADDRESS, USER, PASS, DBNAME) with the same server/DB/creds.
From this article, I eventually managed to get it working using windows authentication with my personal account, but I still can't get it to work using our service account. Does anyone have any insight into why the Python app can connect but the Java one can't?
pymssql is built on top of FreeTDS. Both FreeTDS and jTDS support an older Windows authentication scheme named NTLM, while current versions of Microsoft's JDBC Driver for SQL Server (mssql-jdbc) no longer support that authentication mechanism.
So, given that you've confirmed that pymssql can connect, you should be able to connect from your Java app as Windows user MYDOMAIN\username using jTDS like so:
String myUid = "username", myPwd = "mypassword";
String connUrl = "jdbc:jtds:sqlserver://192.168.1.123:1433/databasename;DOMAIN=MYDOMAIN";
Connection conn = DriverManager.getConnection(connUrl, myUid, myPwd);
To find out the reason of "Login failed for user" one should go to SQL Server error log.
The next row to 18456 error will give you the reason.
The most probably reason of failure in your case is that the server is configurated to use Windows Authentication only
I am trying to connect to a SQL server using Windows authentication. I am doing it through node js on Visual Studio.
The SQL server is on my machine itself.
It had worked fine for the connection string
var config = {
server: '10.2.9.208',
database: 'DFMProAnalyticsCopy',
user: 'sa',
password: 'admin123#',
port: 1433 //default port number
};
But this was only for SQL authentication.
Now for Windows aunthentication, I have this connection string
var config =
"Driver ={SQL Server};Server = 10.2.9.208;Database=DFMProAnalyticsCopy;Trusted_Connection=True;";
This gives me error
Unknown driver SQL Server!
and this connection string
var config =
"Server = 10.2.9.208;Database=DFMProAnalyticsCopy;Trusted_Connection=True;";
gives error
Login failed for user ''
It is trying to attempt SQL authentication when I want Windows authentication. I have Mixed mode authentication ON.
I read at many places but am still unclear about it.
"Login failed for user ''" when trying to use Windows Authentication
Please help me.
EDIT 1:
I cannot use the configuration string as in SQL Server connection with jQuery and node js
because mine is centralised and anyone could be using it, so I need to use Trusted_connection=true or Integrated security = SSPI. I dont have windows login credentials of people using the system.
This worked for me. I had to provide an UID and password in the connection string, else it considered a null string for UID
var config = "Server={IPV4 of server};Database=dbname;Uid=domain\\username;Pwd=pwd";