I am trying to setup apache to connect to a Microsoft SQL server for authentication. This is not ideal but this legacy system has the credentials in MSSQL and that can not change. I have unixODBC setup and working
**odbcinst.ini**
[SQL Server Native Client 11.0]
Description = Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver = /opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
Threading = 1
UsageCount = 1
**odbc.ini**
[mssql]
Driver = SQL Server Native Client 11.0
Server = 192.168.250.200
Database = DBName
When I connect using isql I am able to query the database without issue
isql mssql username password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
In apache I have configured the following
DBDriver odbc
DBDParams "datasource=mssql,user=username;pass=password"
DBDMin 1
DBDKeep 2
DBDMax 10
DBDExptime 300
When I start httpd I get this in the error log
[Thu Dec 10 09:10:35 2015] [dbd_odbc] SQLDriverConnect returned SQL_ERROR (-1) at dbd/apr_dbd_odbc.c:1146 [unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired HYT00 [unixODBC][Microsoft][SQL Server Native Client 11.0]TCP Provider: Error code 0xD 08001 [unixODBC][Microsoft][SQL Server Native Client 11.0]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 confi 08001
[Thu Dec 10 09:10:35.633986 2015] [dbd:error] [pid 15481] (20014)Internal error: AH00629: Can't connect to odbc: [dbd_odbc] SQLDriverConnect returned SQL_ERROR (-1) at dbd/apr_dbd_odbc.c:1146 [unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired HYT00 [unixODBC][Microsoft][SQL Server Native Client 11.0]TCP Provider: Error code 0xD 08001 [unixODBC][Microsoft][SQL Server Native Client 11.0]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 confi 08001
[Thu Dec 10 09:10:35.634054 2015] [dbd:error] [pid 15481] (20014)Internal error: AH00633: failed to initialise
[Thu Dec 10 09:10:35.634200 2015] [dbd:crit] [pid 15481] (20014)Internal error: AH00636: child init failed!
SELinux was blocking the connection from Apache.
Related
Unable to connect to mssql server from qt application in ubuntu 20.04
Sql server located in windows 7
The connection is definitely present, because it was possible to connect through DDbeaver.
Can anyone help me in this situation?
Code:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
db.setConnectOptions();
QString serverName = "566***";
QString ipName = "tcp:192.168.144.101,1433";
QString dbName = "St***";
QString connectionString = QString("DRIVER={ODBC Driver 18 for SQL Server};Server=%1;Database=%2;").arg(ipName).arg(dbName);
db.setDatabaseName(connectionString);
db.setUserName("sa");
db.setPassword("top123TOP");
if (db.open())
{
qDebug() << "Correct connection";
}
else
{
QString error = db.lastError().text();
qDebug() << error;
}
otuput is:
"[Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2746 [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection QODBC3: Unable to connect"
odbcinst.ini
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
the following solution helped:
from:https://github.com/microsoft/msphpsql/issues/1112
This was helpful.
Ubuntu 20.04 PHP 7.4 using the 19.10 drivers for sqlsrv
We have a real old SQL server out there . The SQL Server show's version 10.50.2550.0, i think it's SQL Server 2008 R2. I had to use TLSv1 to connect to the server. I also had to do a "systemctl restart apache2" to get it to take affect. TLSv1.1 did not work with my MSSQL server version.
Error message: Connection failed: SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol]Database Connection Error
edit: /etc/ssl/openssl.cnf
1st line in the file added
openssl_conf = default_conf
End of file added
[default_conf]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT#SECLEVEL=1
Not 100% sure why i had to restart apache2 for it to take effect, but I had to.
systemctl restart apache2
reloaded the page and it works
I have pulled a docker image that runs an MS SQL from docker hub:
docker pull mcr.microsoft.com/mssql/server:2017-latest
docker run --name some-db -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Aamerge1234 -e MSSQL_PID=Developer -d -p 1433:1433 mcr.microsoft.com/mssql/server:2017-latest
The container runs fine, I added a strong password as required.
This is the python code I am using to connect with the database using pyodbc:
import pyodbc
server = 'localhost:1433'
# database = ''
username = 'sa'
password = 'Aamerge1234'
conn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER='+server+';UID='+username+';PWD='+ password)
I have omitted the variable database because mssql creates several.
I tried using the following ODBC drivers:
ODBC Driver 17 for SQL Server
SQL Server
However, it always returns error:
OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [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. (53)')
I've always accessed my University's database using pyodbc in my own machine. However, when I try to use the same code (below) in a Virtual Machine (VMware) I receive an error (translated from Portuguese to English):
import pyodbc
server = 'beirute-01'
database = 'RAIS'
port= '1433'
username = 'gabrielcp2'
password = '*****'
driver= '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
-------------------------------------------------- -------------------------
OperationalError Traceback (most recent call last)
C:\Users\GABRIE~1\AppData\Local\Temp/ipykernel_2064/1387256718.py in <module>
11 driver= 'ODBC Driver 17 for SQL Server'
12
---> 13 cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD=' + password)
14
15 cursor = cnxn.cursor()
OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Timeout Error [258]. (258) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Logon timed out (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Cannot complete login process due to pre-logon response delay (258)')
How could I fix it?
I have installed MSSSQL on Centos 7. Installation is completed but when I am a connection to the SQL via sqlcmd It is giving the following error.
[root#S*03****k ~]# sqlcmd -S 127.0.0.1 -U sa -P H*****3
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 13 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..
root#S*****k ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 699/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 793/master
tcp6 0 0 :::80 :::* LISTEN 704/httpd
tcp6 0 0 :::22 :::* LISTEN 699/sshd
Can anyone help?
After wasting so many days i have come to know that this happens due to Stopped SQL Service. I have tried to start but some how this is not get up.
Every time i checked the MSSQL service is failing i have over 5 GB memory on my virtual server.
r*****k:~# sudo systemctl status mssql-server
● mssql-server.service - Microsoft SQL Server Database Engine
Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Fri 2017-11-17 15:39:39 UTC; 1min 37s ago
Process: 4906 ExecStart=/opt/mssql/bin/sqlservr (code=exited, status=255)
Main PID: 4906 (code=exited, status=255)
Nov 17 15:39:39 SV0*****com systemd[1]: mssql-server.service: Unit entered failed state.
Nov 17 15:39:39 SV0*****com systemd[1]: mssql-server.service: Failed with result 'exit-code'.
Nov 17 15:39:39 SV0*****.com systemd[1]: mssql-server.service: Service hold-off time over, scheduling restart.
Nov 17 15:39:39 SV0*****.com systemd[1]: Stopped Microsoft SQL Server Database Engine.
Nov 17 15:39:39 SV0*****.com systemd[1]: mssql-server.service: Start request repeated too quickly.
Nov 17 15:39:39 SV0*****.com systemd[1]: Failed to start Microsoft SQL Server Database Engine.
Finally, i have created a new virtual machine and SQL Service is working fine. SQL Databases are working as expected.
I've updated the whole scenario (last one was a conflict between i686 and x64 libraries)
Now I have an VPS with a fresh CentOS 6.6 32 bit with unixODBC, FreeTDS and WebGUI installed
I can connect perfectly with SQL Server 2008 through isql and perl scripts.
BUT my goal is to create a database link for WebGUI (an open-source CMS based in perl)
Output for odbcinst -j
unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2
/etc/odbcinst.ini
[FreeTDS]
Description=v0.95.73
Driver=/usr/lib/libtdsodbc.so.0.0.0
UsageCount=1
/etc/odbc.ini
[DSN]
Description=DNS description
Driver=FreeTDS
Server=XX.XX.XX.XX
Database=myDatabase
Port=1433 #sql server default port
TDS_Version=7.3
Trace=Yes
TraceFile=/tmp/sql.log
When I execute this perl script, it runs ok.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBD::ODBC;
my $dsn = "DBI:ODBC:DSN"; # Same DSN as above
my $db_user = "dbuser";
my $db_pass = 'dbpass';
my $dbh = DBI->connect($dsn, $db_user, $db_pass) or die "$DBI::errstr\n";
print "Connected\n";
my $query = "Select * from myTable";
my $sth = $dbh->prepare($query) or die "$DBI::errstr\n";
$sth->execute or die "$DBI::errstr\n";
# go do stuff!
# Close the database
$sth->finish;
$dbh->disconnect;
This is the database link I'm trying to add to WebGUI
When I commit the changes, I get this error in my browser:
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request POST /home.
Reason: Error reading from remote server
modproxy.error.log
[Wed Dec 23 14:15:42 2015] [error] [client IP] proxy: Error reading from remote server returned by /home, referer: http://VPSIP/home?op=editDatabaseLink;dlid=y2Yf1_oEJD6-Wm-T-yHy-w
[Wed Dec 23 14:15:58 2015] [error] [client IP] (20014)Internal error: proxy: error reading status line from remote server 127.0.0.1:8081, referer: http://VPSIP/home?op=editDatabaseLink;dlid=y2Yf1_oEJD6-Wm-T-yHy-w
[Wed Dec 23 14:15:58 2015] [error] [client IP] proxy: Error reading from remote server returned by /home, referer: http://VPSIP/home?op=editDatabaseLink;dlid=y2Yf1_oEJD6-Wm-T-yHy-w
modperl.error.log
[Wed Dec 23 14:15:59 2015] [notice] child pid 7766 exit signal Segmentation fault (11)
Maybe WebGUI is trying to load the /home from SQL Server instead of mysql? (I just want to connect to SQL Server to fetch some products, nothing else)
Any help would be appreciated
Regards
Try: export LD_LIBRARY_PATH=/usr/local/lib
Source
In your odbc.ini, you specify the DRIVER defined in odbcinst.ini.
Try this for odbc.ini:
[DSN]
Description=DNS description
Driver=FreeTDS
Server=XX.XX.XX.XX
Database=myDatabase
Port=1433 #sql server default port
TDS_Version=7.3
Also, be sure you use the right TDS Version for the SQL Server version and FreeTDS version you're using. I'd recommend sticking with 7.2 unless you need 7.3: http://www.freetds.org/userguide/choosingtdsprotocol.htm I've got example odbc.ini, odbcinst.ini and freetds.conf files in this repo, if they help: https://github.com/FlipperPA/django-python3-vagrant/tree/master/examples
Good luck!
OK, just added
use DBD::ODBC;
to the file SQL.pm and WebGUI is able to recognize unixODBC (and FreeTDS, too).
Merry X'Mas!!! :D