I am trying to connect to db2 with php (xampp) on a windows machine, but it is throwing this error:
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
My function is as the following:
function dbConnect($host, $database, $username, $password)
{
try
{
$con = new PDO("odbc:host=$host;dbname=$database", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return true;
}
catch(PDOException $e)
{
return $e->getMessage();
}
}
Notice my php_info is as the following:
By the way, I haven't downloaded/installed any driver. My assumption, by enabling (extension=php_pdo_odbc.dll) in php.ini, it should be accessible.
In windows, you won't need to download any extra drivers as stated in the PHP manual.
Here is the relevant portion from the manual:
On Windows, PDO_ODBC is built into the PHP core by default. It is linked against the Windows ODBC Driver Manager so that PHP can connect to any database cataloged as a System DSN, and is the recommended driver for connecting to Microsoft SQL Server databases.
So, you would need to define a System DSN to your DB2 (this setup might require ODBC driver for DB2 if you don't already have it) and instantiate PDO as follows:
// Replace SYSTEM_DSN_NAME with appropriate name you setup
$con = new PDO("odbc:SYSTEM_DSN_NAME", $username, $password);
Related
Here is a tough one. So I managed to connect to our IBM DB2 database using Windows ODBC DNS method and via the catalogued name. I have the php_pdo_ibm.dll module loaded and it works when connecting doing:
$connection = new PDO('ibm:SomeDB2CataloguedDBName');
The catalogued name (ie: alias) does have the following specified:
db2 update dbm cfg using SSL_CLNT_STASH "C:\somefile.kdb"
db2 update dbm cfg using SSL_CLNT_KEYDB "C:\somefile.kdb"
In the ODBC screen, those parameters are also specified in the Advanced Settings screen:
I know that I can connect using the ODBC connection even if the DB2 DB alias has not been set up as the 3 required SSL parameters are specified there in the db2cli.ini file.
My question is, how can I use the new PDO(.....) in PHP without referencing the DB2 alias nor the ODBC DNS? I expect I would need some sort of special connection string? Thanks.
You can refer to the documentation, which shows an example of connecting via either a DSN alias , or via a connection string with explicit properties.
Both methods should let you make the connection with SSL successfully, assuming your environment is correctly configured.
For connecting with explicitly URL connection string, You need to know the correct Db2 driver name (which may differ from the one shown in the documentation) - your question does not mention which Db2 driver type you are using.
From that documentation page here is a connection URL example:
$db = new PDO(
"ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=testdb;" .
"HOSTNAME=11.22.33.444;PORT=56789;PROTOCOL=TCPIP;UID=testuser;PWD=testpass",
"",
"");
Depending on the Db2 driver name and version, you can add connection properties in the db2dsdriver.cfg XML file (for use with the DSN connection method), or you can place these properties in the connection URL along with any other required properties to make the connection work.
If you are using a Db2 driver that is recent (newer than year 2016) then you can get an SSL connection from CLI applications (like PHP) without needing to use a statically created keystore and without needing to separately deploy the IBM GSK8. This is possible if you have the Db2-instance (or server) certificate in ARM file format and you supply its fully qualified name with the connection attribute SSLServerCertificate="c:/path/to/certificate file"; along with Security=SSL, assuming your target Db2-server environment is already suitably configured. For details, refer to the Db2 Knowledge center for you Db2 server version.
I'm developing an application ASP.NET Core 2.2 on .NET Framework 4.7.2 that needs access to SQL Server, MySQL, Sap Hana, and DB2 thru ODBC.
I have installed the ODBC Driver on Windows, the user fill a form with credentials and send the form to validate the access
The app builds a connection string and opens a connection to validate the access. The problem is that only work with SQL Server when I try with MySQL, Oracle or other I got the error Message "[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
The code I use to validate the connections string is in a separate .NET Framework Library and when I use it in a console app it works and when consuming it in ASP.NET CoreProject don't
using (OdbcConnection connection = new OdbcConnection("Driver={MySQL ODBC 5.1 Driver};server=localhost;Port=3306;Database=sakila;Uid=user;pwd=Password;Option=3;"))
{
try
{
connection.Open();
}
catch (Exception e)
{
// return error message
}
}
I expect it works in ASP.NET Core
While adding new client to bacula (v5.2.6, os Debian Wheezy) and testing configuration with bacula-dir -t -c bacula-dir.conf I'm getting:
bacula-dir: dird.c:954 Could not open Catalog "catalog-test1", database "test1".
bacula-dir: dird.c:959 sqlite.c:182 Database /var/lib/bacula/test1.db does not exist, please create it.
EDIT: Bacula have already two working clients and the problem occurs while adding another one. The same version of bacula director an OS on another server (the same bacula daemons configuration, but the mysql db instead of sqlite3) let me add new clients without creating database for them manually. What should be done to get bacula to automatic catalog creation for new clients?
My Catalog definition for the client:
Catalog {
Name = catalog-test1
dbname = "test1"; dbuser = ""; dbpassword = ""
}
Any advice appreciated.
SQLite DB needs to be created and initialized before first use. It can be done by make commands during manual build or it can be done manually.
In my case (Gentoo Linux) these commands did the trick:
/usr/libexec/bacula/create_bacula_database
/usr/libexec/bacula/make_bacula_tables
See http://www.bacula.org/7.4.x-manuals/en/main/Installing_Configuring_SQLi.html for more details.
Is there a way to connect to SQL server without OBDC driver in perl?
I need to run a script in a machine that i can not install drivers. The specific machine dont have OBDC driver, so I cant run the script
my $dbh = DBI->connect("dbi:ODBC:Driver={SQL Server}"....
I searched on the web but I found nothing. Anyone can help me plz?
If you are running windows, take a look this module:
http://metacpan.org/pod/Win32::ODBC
(First you need to define an ODBC connection in odbc administrator)
With this sample im able to connect:
my $Db="ODBC_CONN";
my $Db_Conex = new Win32::ODBC($Db);
$Db_Conex->Sql("select bar from foo");
while ($Db_Conex->FetchRow()){
my $FooValue = $Db_Conex->Data();
}
Description: I installed SQL Server 2012 on my local machine(Windows 7). At first I installed with Windows authentication. After searching on web, I change to SQL Server authentication and set as: In SQL Server Management Studio->object explorer->security->logins->sa->right click property, select SQL Server authen and set password as "!Abcd1234!" for example.
Then I tried that I can connect by SQL Server authentication with sa/password using Management Studio. But using Perl script I failed.
My simple Perl script as below:
use strict;
use warnings;
use dbi;
my $user = "sa";
my $password = "!Abcd1234!";
my $connect = DBI->connect("dbi:ODBC:Driver={SQL Server};Server=127.0.0.1;UID=$user;PWD=$password")or die "Error: $DBI::errstr\n";
I got error
Error: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (SQL-08001) [state was 08001 now 01000]
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (SQL-01000)
May I get any help or trace method?
Yes, Mitch Wheat, I do enable "sa" account in the status tab. Sorry missing to mention that. I doubt whether my Perl script is correct? I think access locally should have no firewall issues right?
I have connected many a times from perl (running on linux) to the MSSQL server. and while doing so, I would create a DSN manualy on the my Linux box and then write below syntax to connect:
my $dbh = DBI->connect ('dbi:ODBC:odbc-test', 'sqluser_name', 'sqluser_password');
Where, odbc-test is the name of the DSN
And it always worked.
unfortunately I never done any perl DBI connection from windows.
So,
On your windows box, could you create a DSN manually first and then follow above mentioned syntax to connect to the MSSQL server .
You should using ODBC administrator to test the connection first.