Error while connecting MS SQL server 2019 using Perl - sql-server

I am using perl version 5.6.1 (which we are planning to migrate to higher version soon).I am able to connect MS Sql Server 2014 with the below piece of code whereas I am unable to connect MS SQL Server 2019 getting the error posted below
Perl code for db connection testing:
use MSSQL::DBlib;
use MSSQL::Sqllib;
# MS SQL server 2014 the db gets connected using the below stmt where it is throwing error
# for sql server 2019
$dbSession = eval{ (sql_init('xx.xxx.xxx.xx,port no','user','password',"database")};
die "dbconnect.pl: Error at sql_init." if $#;
print "Db connected \n";
Error :
DB-Library error 10013,severity 11: Invalid parameter in DB-Library function reference
DB-Library error 10004,severity 9: Unable to connect :Sql server is unavailable or doesn't exist.SSL security error.
OS error 772:Connection Open (SECDoClientHandshake());
How to resolve this issue in perl version 5.6.1

Forget about MSSQL::Dblib and MSSQL::Sqllib. Microsoft might have dropped backward compatibility for the low-level APIs that these Perl Modules use internally. But I am not an expert here.
One way to do make this possibly work is Perl module DBD::ODBC.
Install a system-wide ODBC data source with the Windows tool "odbcad32.exe". and reference this datasource ("ODBC DSN") by name (e.g. "mydsn") in your Perl Code.
Like this:
use DBI;
$dbh = DBI->connect('dbi:ODBC:DSN=mydsn', 'user', 'password');
Sorry I don't have time to explain in detail how all this needs to be set up.
And the fact that you are using Perl 5.6.1 might indicate that your Windows Platform (including that older version of Microsoft's ODBC codebase) might still be too old for MSSQL 2019.
Besides, ODBC will subtly rewrite your SQL calls in places. So expect some surprises. But this strategy is better than nothing.

Related

How to connect to MS SQLSever from ubuntu using PHP 7

I am trying to connect to Microsoft sqlserver from ubuntu using PHP 7, but i am getting this error,
PHP Fatal error: Uncaught Error: Call to undefined function mssql_connect()
FYI: there is no line called ;extension=php_mssql.dll in php.ini to remove the comment.
you are using linux , so you won't find the line
extension=php_mssql.dll
it perhaps be extension=php_mssql.so ,
the php extensions in ubuntu is suffixed by .so
and for connecting to mssql server from php
you have to take a look at PDO MSSQL
Example #1 PDO_DBLIB DSN examples
The following examples show a PDO_DBLIB DSN for connecting to
Microsoft SQL Server and Sybase databases:
mssql:host=localhost;dbname=testdb
sybase:host=localhost;dbname=testdb
dblib:host=localhost;dbname=testdb
This is likely the same as PHP7 can't connect to MySQL
PHP7 no longer supports the mysql interfaces. You will need to start using mysqli or PDO

Issue creating a connection to SQL server 2014 with ODBC data source and TLS activated

I am trying to create / modify a system data source for my application which needs to connect to our Microsoft SQL Express 2014 database through an ODBC data source.
The connection used to work before we enabled the SSL encryption flow but,
now that we have an encrypted link, the connection does not work anymore.
Here are some details:
We run Microsoft SQL Server express 2014 SP1 with the latest cumulative update (CU #3) (which was necessary so that we could deactivate SSL 3.0 and TLS 1.0 and run only with TLS 1.1 and TLS 1.2)
The database instance is a named instance, configured to run with a TCP/IP connection and a fixed port.
We enabled the "Force Encryption" option and configured the certificate through the "Sql Server Configuration Manager"
We can successfully establish a connection to the database either using Management Studio or the SQL command line utility
We disabled all usage of SSL/TLS prior to version TLS 1.1 done through Microsoft Schannel. This required us to update SQL Express 2014 SP1 to the latest cumulative update (CU #3)
The ODBC data source we try to configure (through ODBC data source Administrator) is a "System DSN" and uses the "SQL server" driver and target the exact same server name as the one working in management studio (and whose server name corresponds to the machine FQDN which is reflected in the certificate CN value)
The Version indicated for the SQL Server ODBC driver is "Microsoft SQL Server ODBC Driver Version 06.03.9600"
I am testing the connection directly through the ODBC data source Administrator tool.
The first test I runs are run on the exact same machine as the one hosting the database server.
We get two consecutive error message in the Microsoft SQL Server Login:
Connection failed:
SQLState : '01000'
SQL Server Error: 771
[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]ConnectionOpen(SECDoClientHandshake()).
Connection failed:
SQLState : '08001'
SQL Server Error: 18
[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]SSL Security error.
I went through all the literature I could find but cannot find a solution.
EDIT 27/01/2016 16:30
Following erg suggestion, I tried to use the last MS SQL Server Native Client version (11.00.2100 on my system), but it still does not resolve the issue. I experience another issue though (whether or not I force the strong encryption on the client side results in the same error):
Running connectivity tests...
Attempting connection
[Microsoft][SQL Server Native Client 11.0]TCP Provider: An existing connection was forcibly closed by the remote host.
[Microsoft][SQL Server Native Client 11.0]Client unable to establish connection
TESTS FAILED!
So, I finally got it working after struggling a little bit more.
First of all, it appears that there is another CU available (CU4) for SQL Server Express 2014 SP1.
I did download it and install it, but it did not resolve my problem: as soon as I deactivated TLS 1.0 and below version ODBC did not work.
Strangely, though the CU3 and installation of .NET 4.6 allowed me to successfully log in in Management Studio, when I tried to execute
the xp_readerrorlog query, it actually failed.
What I did to solve my issue was to follow malthus's answer on another related stack overflow question
https://dba.stackexchange.com/questions/93127/sql-server-service-won-t-start-after-disabling-tls-1-0-and-ssl-3-0 (3rd answer from the top).
I therefore activated the local security policy on my computer and managed to get the links to my SQL db working.
Now, I got IIS working along my own service and client working.
BTW, if somebody needs a more user friendly way of activating SSL/TLS version(s) and cryptographic algorithms on Windows, I stumbled uppon a nice GUI application which does not required to use regedit for it:
https://www.nartac.com/Products/IISCrypto. It's free and I am not a a Nartac Software employee, manager or shareholder.
I hope this will help!
EDIT Feb 25, 2016
It looks like the latest cumulative update (CU5 available at
https://support.microsoft.com/en-us/kb/3130926) removes the need to
activate the FIPS option for the System Cryptography.
I discovered this since I had to deactivate FIPS to enable another required
functionnality while still relying on a TLS 1.2 connection. Indeed, it
appears that activating the FIPS option for the System Cryptography prevents
.NET Framework to successfuly make use of some system algorithms (such as
SHA256Managed).
In addition, according to some discussions seen around the web (i.e.
http://blogs.technet.com/b/secguide/archive/2014/04/07/why-we-re-not-recommending-fips-mode-anymore.aspx)
it is not recommended to activate FIPS (except to strictly comply with
some governmental recommendations) since it breaks applications
relying on non-FIPS validated implementations of cryptographic
algorithms, which, however are provided in Microsoft system libraries.

Using pyodbc to connect to sybase gives Request to start/stop database denied (-75)

Below is my configuration:
Windows 7 x64 running ActiveState Python 2.7.2.5 (64 bit)
Pyodbc 2.1.8
SQL Anywhere 12 driver 12.00.01.3924.
When I try to connect to my sybase database, I get the below error:
cnxn = pyodbc.connect('DRIVER={'+driver+'};HOST='+host+';DATABASE='+database+';UID='+username+';PWD='+password+';PORT='+port)
ProgrammingError: ('42000', '[42000] [Sybase][ODBC Driver][SQL
Anywhere]Request to start/stop database denied (-75)
(SQLDriverConnect); [42000] [Sybase][ODBC Driver][SQL Anywhere]Request
to start/stop database denied (-75)')
I have tried this with different versions of Pyodbc. I also tried with 32 bit versions of Python and Pyodbc, but was not successful. Googling around gave me nothing concrete, though the problem has been around for some time.
How do I connect seamlessly? I have seen it working some time back on Windows XP, but I do not remember the python and pyodbc versions now. I tried on Windows XP with the same set of above but i get the same error. Please help!!!
I'm landing on this page every time I google for "pyodbc sybase example" and every time I have to re-invent the answer, so let me just post what actually worked.
Tested on py2.7-Linux, py2.7-win and py3.5-win. Since this question is now 3 years old I could only test it on somewhat later version of pyodbc 4.0.17 (from both pypi and conda) and Sybase ASE 15.
It's mostly based on Brian's answer (thanks Bryan!), but to get the "Tadam!" effect you need to pass the port separately:
cnxn = pyodbc.connect(driver=driver, server=host, port=port,
database=database, uid=username, pwd=password)
To get list of drivers, run:
pyodbc.drivers()
The connection string attributes don't match anything I see here or here for Sybase, but I also don't have an instance to test, so take the following with a grain of salt.
Try this syntax to using keywords for the connect method so you don't have to keep up with Sybase-specific attributes:
server = "{0}:{1}".format(host, port)
cnxn = pyodbc.connect(driver=driver, server=server, database=database,
uid=username, pwd=password)
Also note that I'm combining the host and port as formatted in this example.
This is what I did in a Windows 7 machine to connect to sybase database using pyodbc
Install Sybase ASE ODBC driver (Check with your IT whether they have this driver)
Install Python27 32 bit (I installed the Anaconda distribution Anaconda2-5.3.1-Windows-x86.exe)
setup DSN (create new data source using Sybase ASE ODBC driver). Get all the required parameter from appropriate personnel.
Test connect to make sure it connects to sybase database you are looking for.
Here is the sample python code that worked after doing all the above steps.
import pyodbc
syb_con = pyodbc.connect('DSN=yourDSNname', uid='username', pwd='password')
cursor = syb_con.cursor()
cursor.execute("select count(*) from tbl_name)

I/O Error: SSO Failed: SSPI Not Initialized

I am using pentaho data integration 4.1 (Kettle) to build an ETL system. My customer requires connecting to database (MS SQL Server) using window authentication, I knew that Kettle supported it . However when I run my Kettle job, it throws the exception
"I/O Error: SSO Failed: SSPI Not Initialized".
From an article on a forum, I copy library sqljdbc_auth.dll into jre/bin folder. The result is quite good, I can use window authentication to connect to SQL server. But this function is not stable, I mean sometimes it works well, sometimes it throws exception
"I/O Error: SSO Failed: SSPI Not Initialized".
Please tell me how to fix this error.
Thank you.
To connect to SQL Server 2008, I had to install the 'Microsoft JDBC Driver 4.0 for SQL Server' and then add the path to sqljdbc_auth.dll to Spoon.bat in %PENTAHO_DI_JAVA_OPTIONS%. Like this:
set OPT=%PENTAHO_DI_JAVA_OPTIONS% "-Djava.library.path=%LIBSPATH%;C:\PROGRA~1\MICROS~1.0FO\sqljdbc_4.0\enu\auth\x86;C:\PROGRA~1\IBM\SQLLIB\BIN" "-DKETTLE_HOME=%KETTLE_HOME%" "-DKETTLE_REPOSITORY=%KETTLE_REPOSITORY%" "-DKETTLE_USER=%KETTLE_USER%" "-DKETTLE_PASSWORD=%KETTLE_PASSWORD%" "-DKETTLE_PLUGIN_PACKAGES=%KETTLE_PLUGIN_PACKAGES%" "-DKETTLE_LOG_SIZE_LIMIT=%KETTLE_LOG_SIZE_LIMIT%"
Ugly, but that's Java under Windows for you. Works quite reliably now though.
Are you using the JTDS driver? Try that combined with the ntlmauth.dll - that works great for us when running PDI on Windows Server 2003 connecting to various remote sqlserver databases.
We place the DLL in this folder:
libswt\win64
I've had the same issue while using JDBC 1.2.2 with MSSQL 2008. It turns out that there is a bug in the driver, making it randomly crash if you initialize it with more than one connection.
If we used only one initial connection to the DB this error never presented itself.
The issue is fixed in a later versions of JDBC. We currently use 1.3.0 and I/O Error: SSO Failed: SSPI Not Initialized never comes up.

How to fix native client error 'Connection is busy with results for another command'?

I'm getting a Connection Busy With Results From Another Command error from a SQLServer Native Client driver when a SSIS package is running. Only when talking to SQLServer 2000. A different part that talks to SQLServer 2005 seems to always run fine. Any thoughts?
As I just found out, this can also happen on SQL 2005 if you do not have MARS enabled. I never even knew that it was disabled by default, but it is. And make sure you are using the
"NATIVE OLEDB\SQL Native Client" connection type. If you're using the "OLEDB.1" type connection (or whatever...) MARS is not even an option, and you get the SQL 2000 behavior, which is nasty.
You can enable MARS by opening the connection properties, and clicking "All", and scolling down in Management Studio.
I know your question has long since been answered, but I'm just throwing this in for the next sucker like me who gets burned by this.
Had this error today with MS ODBC Driver 11 for SQL Server for Linux to SQL Server connection. Wanted to help next searcher considering this was the first Google search result when I made the search.
You need to set MARS_Connection in /etc/odbc.ini as following:
[ConnName]
Driver=ODBC Driver 11 for SQL Server
Server=192.168.2.218,1433
Database=DBNameHere
MARS_Connection=yes
Speaking of MS ODBC Linux Driver: It is a complete PITA to deal with it but I insisted using native solution. I experienced too many walls especially working with ZF2, however, every trouble has a solution with the driver I can say. Just to encourage people using it instead quickly give up.
If somebody met this annoying bug while using PHP PDO with ODBC, then use closeCursor() method after query execution.
Microsoft KB article 822668 is relevant here:
FIX: "Connection is busy with results for another command" error message occurs when you run a linked server query
Symptoms
Under stress conditions, you may receive the following error message when you perform linked server activity:
Server: Msg 7399, Level 16, State 1, Procedure <storedProcedureName>, Line 18 OLE DB provider 'SQLOLEDB' reported an error.
OLE/DB Provider 'SQLOLEDB' ::GetSchemaLock returned 0x80004005:
OLE DB provider SQLOLEDB supported the Schema Lock interface, but returned 0x80004005 for GetSchemaLock .].
OLE/DB provider returned message: Connection is busy with results for another command
OLE DB error trace [OLE/DB Provider 'SQLOLEDB' ::CreateSession returned 0x80004005.
Note The OLE DB source of the error may vary. However, all variations of the error message include the text "Connection is busy with results for another command".
Resolution
To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000.
As noted there, the problem was first corrected in SQL Server 2000 Service Pack 4.
This blog post by Mark Meyerovich, a Senior Software Engineer at RDA Corp, also provides some insight (now archived, because the original link went dead):
SQL Server service pack upgrade
A quick search on Google turns up the following article (http://support.microsoft.com/kb/822668):
FIX: "Connection is busy with results for another command" error message occurs when you run a linked server query.
It basically implies the issue is a bug and recommends an upgrade to Service Pack 4. We have started out with SQL Server 2000 SP3 and we do have some linked servers in the equation, so we give it a try. After the upgrade to SP4 – same result.
Just for information if somebody else have the problem. I tried connecting via NetCobol of Fujitsu on an SQLEXPRESS via ODBC with embedded sql and to solve the problem I had to change a value in the registry namely
\HKLM\Software\ODBC\ODBC.INI\MyDSN
with MyDSN as a string value:
Name - MARS_Connection
Value - Yes
I just put the information here if it can help.

Resources