How do I specify a database name with a hyphen in unixODBC? - sql-server

I have a SQL Server database named pm-eng that I need to connect to from a linux box. I've setup unixODBC and configured my odbc.ini as follows:
[pm_production]
Driver = FreeTDS
Server = mssql.server
Database = pm-eng
When I test with iSQL, I get an error connecting saying that the the 'pm' database does not exist. I've tried wrapping the database name in [] and quotes with no luck. Ideally I would just change the name of the DB but that is not possible in this environment. I've verified my connection with a DB name that is not hyphenated and it works fine. Is it possible to connect to ODBC DSNs with hyphenated DB names?

Since you're connecting to a MSSQL database maybe you can try this:
[pm_production]
Driver = FreeTDS
Server = mssql.server
And then connect with a user who's default Database is pm-eng
According to documentation found on MSDN: "If Database is not specified, the default database defined for the login is used."

This turned out to be an issue with FreeTDS, not unixODBC. I needed to specify a TDS_Version in the odbc.ini file and it started working. Final config looks like this:
[pm_production]
Driver = FreeTDS
Server = mssql.server
Database = pm-eng
TDS_Version = 8.0

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)

i can't connect to Azure database in QT

My database is on an Azure server. And I'm trying to connect to it via an ODBC driver (by the way, I tried to install it manually, but I couldn't get it. They say it's built in). I get the following error: "Data source not found and no default ODBC driver specified: Unable to connect"
dataBaseKnowFood = QSqlDatabase::addDatabase("QODBC");
QString connectString = QStringLiteral("myconnectionstring");
dataBaseKnowFood.setDatabaseName(connectString);
dataBaseKnowFood.setPassword("dgf");
dataBaseKnowFood.setUserName("gidgfsg");
if (!dataBaseKnowFood.open())
{
QMessageBox::critical(this, "Programm", dataBaseKnowFood.lastError().text());
}
Problem solved. It was required to update this driver and indicate the version of the updated driver in the connection string.

Lazarus (Pascal) How to connect to SQL Server using ODBC or TMSSQLConnection?

I am using SQL Server 2008 R2 and my PC is 32 bit. I created an ODBC Data Source in the "Administrative Tools". I used the server name (My PC name)\SQL2008R2 which is the instance name and I used Windows Authentication instead of using username and password.
In Lazarus, I used the ODBC Connection and when I try to set the property "Connected" to true I get this error:
And I tried to use also the SQL Server connection with the "dblib.dll" and got an error.
Note: I tried to paste the dll file in C:\Windows\System32 folder and in the C:\lazarus but still getting same error.
I've no experience with Pascal/Lazarus, but the ODBC error message in the first screenshot suggests that the property names in the Lazarus configuration screen don't match the property names used by ODBC; the error says:
Could not connect with connection string "DSN=jbs..."
Based on the screenshot of your ODBC system DSN, the DSN name is DBSource. Try setting value of the DatabaseName to DBSource in the Lazarus ODBC connection configuration screen.

Connecting to SQL Server using PHP, ODBC, and Windows authentication

I'm trying to use PHP to connect to an ODBC data source using Windows authentication. I can connect just fine to the server in SQL Server so I know it's running. When I try to run the command
$link = odbc_connect("my_odbc","","");
I get the error:
"Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user ''., SQL state 28000 in SQLConnect in C:\Users..."
I tried:
$link = odbc_connect("Driver={ODBC Driver 11 for SQL Server};
Server='my_odbc';Integrated Security=SSPI","","");
Which returned the message:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. , SQL state 08001 in SQLConnect in C:\Users..."
Not sure what I'm doing wrong.
my_odbc is a SQL Server (2008) on a different machine. I don't have admin privileges on that database so I can't change anything on that end (such as enabling SQL Server authentication).
I am running Windows 7 and using PHP Version 5.6.12
phpinfo() indicates that ODBC Support is enabled as well as pdo_sqlsrv support
Maybe you should try PDO (the performance difference isn't that great) with SQLsrv plugin (this what I'm using to connect to my other boss' software which use SQL Server 2008 database):
$connection = new PDO("sqlsrv:Server=" . $this->sourceServer . ";Database=" . $this->sourceDB, $this->sourceUser, $this->sourcePW);
$connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
You can download the plugin here
https://www.microsoft.com/en-ca/download/details.aspx?id=36434
In Xampp, you must copy the dll in that folder:
C:\xampp\php\ext
And you must add that line to your php.ini
extension = php_pdo_sqlsrv_56_ts.dll
Note: Don't forget to restart your server so it can take in account the new php.ini file.
Let me know if it works for you
This error is a General Error that arises due to unable to establish connect to the server for some reasons. Its important to know what server are you using with PHP and the application used with it. Example Apache, Xampp or Wamp etc.
Here are somethings you could try like.
Let me brief, below are the reference links.
Check whether it pings
Enable TCP/IP connection SQL Server Configuration if not enabled. To do so, Open SQL Server Configuration Manager -> SQL Server Network
Configuration->Protocols for SQL server->TCP/IP(set to enabled).
Restart SQL services.
Enable Remote Connection from server
Open the Port, To do so Windows Firewall Settings-> Exceptions -> add a Port (Name:SQL;Port:1433;TCP) then from Exceptions tick SQL and save.
Enable running browser services.SQL Server Configuration Manager -> SQL Server Services - > SQL Server Browser set to running.
defining Port in connection string
add instance name with machine name if more than one instance is being used
sample
$user = 'username';
$pass = 'password';
//Use the machine name and instance if multiple instances are used
$server = 'serverName\instanceName';
//Define Port
$port='Port=1433';
$database = 'database';
$connection_string = "DRIVER={ODBC Driver 11 for SQL Server};SERVER=$server;$port;DATABASE=$database";
$conn = odbc_connect($connection_string,$user,$pass);
here are useful links that i found regarding the issue
resolving could not open a connection to sql server-errors
sql server provider named pipes provider error
Have a look at these links too
Named Pipes Provider: Could not open a connection to SQL Server [53]
Someone had the same error message and asked and answered his own question here.
To quote...
I´m sorry for the troubles.
The problem was, that I was using SQL Server Native Client 11.0 as driver. I switched it to SQL Server and now it works :/
Hopefully this at least helps someone, being in a similar problem....
A significant omission from your question is how you are running PHP and with which credentials.
Assuming you are using IIS or Apache (or another web server), then your PHP process is probably running under the local system account:
Since this account is local it doesn't have any authorisation to access your remote SQL Server.
You could alter the IIS/Apache service to run with the credentials (yours?) that are authorised to connect to SQL Server, but be aware this might cause other permissions issues with the service as well as being a problem if you change your password in the future.
Try running a test script from the command line (which should run with your credentials by default) to determine where the problem is:
php -r "var_dump(odbc_connect(...));"
Look at the regedit HKLM/SOFTWARE/ODBC
what is your folder name ?
If there is a "SQL Server Native Client 11.0" then you have to write your php code like
odbc_connect("Driver={SQL Server Native Client 11.0};Server=ip;Database=db;", "user", "pass");
However some of the server like server 2008 will be record this odbc like
ODBC Driver 11 for SQL Server
Then you have to replace SQL Server Native Client 11.0 by ODBC Driver 11 for SQL Server.
You have to create an ODBC interface first. In principle, this should also work without a user and pw. If defined in interface.
$pdo = new PDO('odbc:dsnName','user','pw');
Enable in IIS on Manager PHP o PDO_ODBC:
I have authenticated by Windows with following PHP statement:
$ Conn = new PDO ("odbc: Driver = {SQL Server}; Server = JAMILI-PC \ SQLEXPRESS; null; null");
I am using Windows 2008.
I hope it solves your problem.

How do I access a SQL Server database from a Perl script in Linux?

I have a Perl script on a Linux (Ubuntu 8.10) machine and I need to write data to a SQL Server Database. I've been trying to use the DBD::ODBC module but I can't get it to connect. Where can I get a free/open source driver to use to use for the ODBC connection or is there another way to do this from Perl on Linux?
I connect to SQL Server 2005 with the stack of unixODBC, freeTDS (this is the driver) and DBD::ODBC.
After you install these components, edit /etc/unixODBC/odbc.ini to read like this:
[DNS]
Description = my database
Driver = /usr/lib/libtdsodbc.so #path to freeTDS driver
Server = ServerName
Database = DatabaseName
Port = 1433 #sql server default port
TDS_Version = 9.0 #9.0 is sql server 2005
try domain login = yes
try server login = yes
nt domain = DOMAIN
If all goes well, you should be able to connect with:
$dbh = DBI->connect('dbi:ODBC:DNS', "userName", "passWord");
Good luck!
Use the DBD::Sybase module, at one point Sybase and MS SQL Server shared a common codebase.
You may also want to investigate the open source FreeTDS libraries. See the FreeTDS FAQ Question "Which Perl library should I use".

Resources