Windows PostgreSQL Unicode ODBC driver commection string CommLog not working - postgresql

CommLog set to 1 in connection string BUT no log file being written anywhere.
What am I missing here?
I wonder how does the driver figure out the log file path to write to? Am I supposed to tweak the system wide ODBC settings to make this work?
ODBC;DSN=overload;DATABASE=overload;SERVER=192.168.34.18;PORT=5432;CA=r;A6=;A7=100;A8=4096;B0=255;B1=8190;BI=0;C2=dd_;CX=1c502bb;A1=7.4;UID=pavel#access;PWD=********;CommLog=1

Related

Passing ssl certificates paths to PostgreSQL ODBC driver

I'm attempting to connect to a Postgres database that requires the client pass the paths to client and server SSL certificates using the ODBC driver for postgres. I'm using psqlodbc v11 x86 on Windows 10. I need to have three options passed to the ODBC driver sslrootcert, sslcert, and sslkey. I know that the paths are not being passed by the odbc driver since when I connect using the following connection string where I specify the pqopts it is able to connect.
Driver={PostgreSQL UNICODE};Server=XXXX;Port=5432;Database=XXXX;Uid=XXXX;Pwd=XXX;sslmode=verify-ca;pqopt={sslrootcert=C:\\ssl\\pgSQL.ca.cert sslcert=C:\\ssl\\pgSQL.cert sslkey=C:\\ssl\\pgSQL.key}
According to the document section
Advanced Options 3/3 Dialog Box->Libpq parameters, I should be able to pass the parameters by typing the values within the braces directly into the text box. It displays the error message saying that it cannot find the certificate because it is looking in the default location and is not using the value that was provided in the Libpq text box. Am I doing something wrong? Any advise on how to connect passing client certificates would be greatly appreciated.
Answering this in case anyone else finds this useful. The problem seems to be that the Test button on the ODBC Driver doesn't take the options set in the libpq parameters into account and just uses the default settings. When I saved the ODBC connection closed the ODBC Data Source Administrator window and used the connection from a different program it was able to connect successfully.

Connecting to a SQL Server DB

I’ve been trying to connect to a SQL Server DB in Perl since yesterday, and it’s a failure. I use the DBI->connect function, but I got error saying the data source and the driver are not found. I use that string:
'dbi:ODBC:mydb:myhost\myinstance'
I’m not really sure the string’s correct. Any idea?
EDIT: here’s the error I got:
DBI connect('***:***\***','',...) failed: [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified (SQL-IM002)
at Collector.pl line 137
The format of the DBI connect string for ODBC is 'dbi:ODBC:DSN_name' or 'dbi:ODBC:DSN=DSN_name' (for connections using Data Source Names (DSNs). In that case DSN_name needs to be the name of a data source you created with the ODBC administrator. This situation is slightly more complicated in Windows 64 bit environments as there are 2 ODBC administrators, one for 32 bit applications and one for 64 bit applications (you cannot mix the two).
So, first, work out if you Perl is 32 bit or 64 bit executable - you can usually see this from the output of perl -V (look for archname but there are other indications too). Then find the right ODBC Administrator depending on how your perl was built and create the data source with it. Lastly, change your DBI connect string as above.
There are also so called DSN-less connections that do not require a DSN but instead you name the DRIVER and any attributes required to connect to the database.
There differences in what DBD::ODBC does if you use 'dbi:ODBC:DSN_name' instead of 'dbi:ODBC:DSN=DSN_name' which you can read about ODBC - The Connection Process.
You can find out more about 32/64 bit ODBC and where to find the right driver manager at 64 bit ODBC. You can find out about DBD::ODBC and connections at Drivers, Data Sources and Connection - Perl DBI/DBD::ODBC Tutorial Part 1.
Well this seems to work ok,
use DBI;
#
$dbh = DBI->connect( "dbi:mysql:DBNAME", "root", "password" )
or die "Connection Error $DBI::errstr\n";
N.B. Please Check you have the required modules installed.

MySQL Dump and Import not preserving encoding?

I am trying to copy a table from on MySQL database on a remote machine to another MySQL database on my local machine. I noticed that after importing the dump to my local machine, there were characters like ’ instead of single quotes.
I assumed this was an encoding issue, so I went into both databases and ran show create table posts, near the end of both, I saw CHARSET=utf8. Also, I ran file -i on the dump file, both before and after scping it to my local machine, and they were both utf8.
However, when I import this file, I get this before:
attendees—policy makers,
and after:
attendees—policy makers,
I am not sure why this is happening, everything is using utf8, what am I missing?
EDIT: I am using mysql Ver 14.12 Distrib 5.0.75, for debian-linux-gnu (x86_64) remotely, and mysql Ver 14.14 Distrib 5.5.25a, for osx10.7 (i386) locally.
On both systems you must check that your connection encoding is correct:
SHOW VARIABLES LIKE 'character_set_%'
Usually seeing characters like that is the result of double-encoding. Make sure you can match up the connection and client encoding to be exactly the same. There is a number of command line options that can facilitate this, or if you're using a driver or client, something in there can tweak it.

How do i connect Perl with an Excel file (*.xlsx or *.xls) using ODBC?

I have been asked to look into using ODBC as a database driver to be able to use SQL on an Excel workbook. I have seen a number of people using OLE as a driver, but the only ODBC walkthroughs I've seen are regarding connecting to an MSSQL Server or MySQL.
I have confirmed that i have ODBC setup and that it below are the ODBC drivers i have available. Can anyone shed some light on connecting to an XLS file?
Available Drivers:
DBI Drivers:
Chart, DBM, ExampleP, File, ODBC, Oracle, Proxy, SQLite, SQLite2, Sponge, mysql
ODBC Drivers:
DBI:ODBC:MS Access Database
DBI:ODBC:Excel Files
DBI:ODBC:dBASE Files
DBI:ODBC:Visio Database Samples
DBI:ODBC:Xtreme Sample Database 2003
DBI:ODBC:Xtreme Sample Database 2008
inside test.pl
my $dbh = DBI->connect('DBI:ODBC:Driver{Excel Files}MyExcelFile');
I'm not in front of a Windows machine right now but this is approximately what you need to do. Find the ODBC Administrator and depending on whether you are going to be the only one running your Perl or others as well create a USER or SYSTEM DSN. Select Excel as the driver from the list and click add then fill in any required fields you are asked for - at least the location of the excel file. Give the DSN a name.
Now use DBI->connect('dbi:ODBC:DSN=name_you_gave_DSN');
Once connected, read about odbc_out_connect_string attribute which returns the ODBC out connection string. It will look something like:
Driver={Excel Files};workbook=c:\x.xls;something=somethingelse;
You can use that string instead of DSN=name_you_have_DSN in the connect call now and you'll no longer need the DSN you created - so called DSN-less connection.
After that there are loads of tutorials on using DBD::ODBC including the ones at http://www.easysoft.com/developer/languages/perl/index.html
I use the Microsoft Excel Driver outlined here in what's called a "DSN-less connection" where only the driver is specified and you specify the Excel file as a parameter in the connection string itself: http://www.connectionstrings.com/excel-2007-odbc/
my $file = 'c:\temp\myfile.xslx';
my $dbh = DBI->connect('dbi:ODBC:driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ='.$file.';');
my $sth = $dbh->prepare( "SELECT * FROM [Sheet1\$]" );
$sth->execute();
while (my $row = $sth->fetchrow_hashref) {
print Dumper( \$row );
}
Watch out if you are running 64 bit perl and need to access a 32 bit ODBC driver though. You can't mix bits like that and have to resort to using 32 bit perl or some kind of ODBC bridge: Can i use a 32 Bit ODBC Driver for my 64 Bit app
More recently I have had to install the Microsoft Access Redistributable to get the Excel driver on Windows 10: https://stackoverflow.com/a/54757113/74585
To connect you need connect string. There you can use DSN version ad bihica described, or show what driver you can use and use driver specific properties. For Excel this can look like:
Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\MyExcel.xls;DefaultDir=c:\mypath;
You will find more examples at: http://www.connectionstrings.com/excel#p86

Data source name not found and no default driver specified

I am trying to connect to list the servers on my network using osql.exe -L. Instead of a list of servers, however, I get the following error:
[ODBC Driver Manager] Data source name not found and no default driver specified
I'm not sure what's causing this problem - any pointers leading in the right direction will be helpful. Thanks so much!
The DSN is case sensitive, make sure your putting in the right name. It should match whatever you have in your odbc.ini file (unix) or in the "ODBC Data Source Administrator" (windows).