How I do properly connect to an SQL server using Windows authentication? - c++

I'm writing a program in Qt that connects to a local database and writes to it using QSqlDatabase, but I've been unable to get a working connection between my program and the server.
qdb = QSqlDatabase::addDatabase("QODBC");
qdb.setConnectOptions();
QString serverName = "KIRKWOOD\TESTCLOUD";
QString ipName = "tcp:10.150.94.197,1433";
QString dbName = "Puma";
QString connectionString = QString("DRIVER={ODBC Driver 17 for SQL Server};Server=%1;Database=%2;Trusted_Connection=Yes;").arg(ipName).arg(dbName);
qdb.setDatabaseName(connectionString);
bool connectionSuccessful = qdb.open();
if (connectionSuccessful) {
writeLogWithNewLine("Connected to database.");
}
else {
writeLog("Failed to connect to database.");
writeLogWithNewLine(qdb.lastError().text());
}
When I run this code I get the following error in my log:
"Failed to connect to database.
[Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it. [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired QODBC3: Unable to connect"
When I replace ipName with serverName I get this error:
"Failed to connect to database.
[Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired QODBC3: Unable to connect"
When I change the driver to "SQL Server" I get this error:
"Failed to connect to database.
[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to connect"
I've done a lot of research and made a lot of changes to my code, from changing the Driver type to changing the formatting of "Trusted_Connection=Yes" to "Integrated Security=True" but I've had no luck getting anything much different from these errors.
This is frustrating because in this same program I was able to connect to a dummy database using SQL authentication perfectly fine, and on top of that, using this same machine I'm able to connect to the database through Visual Studio's Server Explorer. I've even directly copy pasted the connection string from visual studio but still got nothing. Is there something else I need to do here?
I would greatly appreciate feedback.

Related

Google Cloud Fusion: Failed to explore connection. Error: "Failed to create connection to database via connection string:

I am trying to set up a connection to a postgres DB from Cloud Fusion. I have what I think is the appropriate JDBC driver. I am going through the Wrangler UI. I keep getting this error message: Failed to explore connection. Error: "Failed to create connection to database via connection string: jdbc:postgresql://XX.XXX.X.XX:PORT/TABLE_NAME and arguments: {user=USERNAME}. Error: SocketTimeoutException: connect timed out."
It appears my password is being sent. Is this a jdbc issues or something else? All help appreciated.
Thanks!

Google big query data server connection with cognos Analytics 1116

I am trying to create google big query data server connection with cognos analytics on cognos portal but i am getting below error . I have followed all steps . Placed json in the driver folder inside cognos install directory along with all the simba jdbc driver but not sure where i am missing .I have installed simba odbc drivers as well , system dsn is also showing simba driver but still getting connection refused. My cognos setup is installed on windows server 2019 data center which is Virtual Machine hosted on GCP and port 80,443 traffic is also enabled.
XQE-DS-0006 Unable to logon to the data source.
[Simba]JDBC Connection Refused: [Simba]JDBC Required Connection Key(s): OAuthServiceAcctEmail; [Simba]JDBC Optional Connection Key(s): AdditionalProjects, AllowLargeResults, DefaultDataset, EnableHighThroughPutAPI, FetchThreadsPerResultSet, ForceHTAPI, HighThroughPutMinTableSize, IgnoreTransactions, KMSKeyName, Language, LargeResultDataset, LargeResultsDatasetExpirationTime, LargeResultTable, MaxResults, OAuthAccessToken, OAuthClientId, OAuthClientSecret, OAuthRefreshToken, ProxyHost, RequestGoogleDriveScope, StringColumnLength, Timeout, TimestampFallback, useQueryCache
Please see the following document which goes through the connection step by step.
Google big query data server connection with cognos Analytics 1116
Its most likely the JSON file is not in the JDBC connection URL.

How to get valid ODBC connection string from Microsoft Windows "ODBC Data Source Administrator (64-bit)" - Firebird case?

I have installed Firebird ODBC driver on my computer and I have entered data for the new connection inside Microsoft Windows "ODBC Data Source Administrator (64-bit)" and "Test Connection" was successful and I can also use this DSN (Data Source Name) from Power BI Desktop.
But now I am trying to use Firebird ODBC driver from other application (custom M Language connector, that works atop Firebird ODBC driver and that I develop to enable DirectQuery access mode in Power BI Desktop, ODBC drivers natively does not support DirectQuery access mode) and there I am required to provide ODBC connection string as one string.
I have formed (more or less intuitively) such string, e.g.:
User=SYSDBA;Password=masterkey;Database=D:\DB\ERP.FDB;DataSource=192.168.1.3;Port=3050;Dialect=3;Charset=UTF8;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;Initial Catalog=test;
But this string is rejected by Power BI Desktop with error message:
Unable to connect
We encountered an error while trying to connect.
Details: "ODBC: ERROR [08004] [ODBC Firebird Driver]connection lost to database
ERROR [01S00] [ODBC Firebird Driver]Invalid connection string attribute
ERROR [01S00] [ODBC Firebird Driver]Invalid connection string attribute"
My intention and wish is to grab already existing ODBC connection string that sits inside "ODBC Data Source Administrator (64-bit)" and use it for my connection, but the problem is that "ODBC Data Source Administrator (64-bit)" does not provide easily accessible way to get such fully formatted connection string from DSN entry.
So, my question is: how to read connection string from "ODBC Data Source Administrator (64-bit)" DSN entry. Specifically, how to do it from page that is used for Firebird ODBC driver.
You should read https://firebirdsql.org/file/documentation/html/en/refdocs/fbodbc20/firebird-odbc-driver-20-manual.html#fbodbc205-connection
If you already have configured DSN, you don't need anything else, just use "DSN=xxxx;".

Connecting to SAS libraries via ODBC

I am new to ODBC and trying to make a DSN in Windows ODBC administrator to call it from R using "RODBC" or similar R-packages.
I am able to find the "server name" and "database name" for anything on "SQL Server" driver. However, "SAS" driver does not let me find explicit names for server and database names. All I know is the URI where the data set is stored, also I can get the host name of the SAS server that stores the databases and its port. Is there a way to add it as a DSN or even call it directly from R? I have tried several permutations of these name and addresses but I constantly get the same error that odbc connection was not successful.
For example, after I followed the steps to add SAS server in ODBC administrator, and I used RODBC package in R, I got this result
odbcConnect("mydbname")
[1] -1
Warning message:
In RODBC::odbcDriverConnect("DSN=mydbname") : ODBC connection failed

ColdFusion DSN with DB2 via ODBC

I'm attempting to connect a ColdFusion application to a DB2 ODBC DSN.
Here's my error message:
Connection verification failed for data source: <DSN NAME>
java.sql.SQLException: [Macromedia][SequeLink JDBC Driver][ODBC Socket][IBM][CLI Driver] SQL30082N Attempt to establish connection failed with security reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001
The root cause was that: java.sql.SQLException: [Macromedia][SequeLink JDBC Driver][ODBC Socket][IBM][CLI Driver] SQL30082N Attempt to establish connection failed with security reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001
I've installed DB2 client tools on the server ColdFusion runs on. I've verified the credentials are correct.
I'm not a DB2 guy, but have you seen the Coldfusion DB2 Universal Driver doc located here?
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=datasources_ADV_MJS_07.html
Based on your comments, you're using ODBC Socket instead. So while this isn't 1 to 1 what you're asking, it might have something useful: Configure Solaris to DB2 ODBC
http://kb2.adobe.com/cps/171/tn_17188.html
The other thing to keep in mind is that DB2 is only supported in CF Enterprise and Developer Editions. http://www.adobe.com/products/coldfusion/systemreqs/
http://kb2.adobe.com/cps/801/80121c8.html
This CFMX doc ended up being what we went with to get it working.
Thanks to SO for pointing us in the right direction.