how to catch specific pyodbc error message

This worked for me. try: cnxn = pyodbc.connect(…) except pyodbc.Error as ex: sqlstate = ex.args[0] if sqlstate == ‘28000’: print(“LDAP Connection failed: check password”) There are different SQLSTATES and you can have if-else statements to print out the cause. Similarly, try: cnxn = pyodbc.connect(…) except pyodbc.Error as ex: sqlstate = ex.args[1] print(sqlstate) will give you … Read more

How do I create an ODBC DSN entry using C#?

I actually solved this myself in the end by manipulating the registry. I’ve created a class to contain the functionality, the contents of which I’ve included here: ///<summary> /// Class to assist with creation and removal of ODBC DSN entries ///</summary> public static class ODBCManager { private const string ODBC_INI_REG_PATH = “SOFTWARE\\ODBC\\ODBC.INI\\”; private const string … Read more

ODBC prepared statements in PHP

Try removing the single quotes from the query string and adding them to the parameter value itself: $pstmt=odbc_prepare($odb_con,”select * from configured where param_name=?”); $res=odbc_execute($pstmt,array(” ‘version'”)); var_dump($res); //bool(true) $row = odbc_fetch_array($pstmt); var_dump($row); //bool(false) The single space character at the beginning of the parameter value is very important–if the space is not there, it will treat the … Read more

Linux – PHP 7.0 and MSSQL (Microsoft SQL)

Microsoft has PHP Linux Drivers for SQL Server for PHP 7 and above on PECL. These are production ready. To download them, follow these steps: Ubuntu 16.04: sudo su curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add – curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list exit sudo apt-get update sudo ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev sudo pecl install sqlsrv … Read more

Creating a custom ODBC driver

Another option: Instead of creating a ODBC driver, implement a back end that talks the wire protocol that another database (Postgresql or MySQL for instance) uses. Your users can then download and use for instance the Postgresql ODBC driver. Exactly what back-end database you choose to emulate should probably depend the most on how well … Read more

How do I change a Crystal Report’s ODBC database connection at runtime?

After even more research I found that there was a two part answer. PART 1 If you are connecting to PostgreSQL via ODBC (the only way Crystal Reports can pull data from PostgreSQL as of the time of this writing) using the data owner you then you can use the following code: reportDoc.Load(report); reportDoc.DataSourceConnections[0].SetConnection(“Driver={PostgreSQL ANSI};Server=myServer;Port=5432;”, … Read more

How to connect PHP with Microsoft Access database

If you are just getting started with a new project then I would suggest that you use PDO instead of the old odbc_exec() approach. Here is a simple example: <?php $bits = 8 * PHP_INT_SIZE; echo “(Info: This script is running as $bits-bit.)\r\n\r\n”; $connStr=”odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};” . ‘Dbq=C:\\Users\\Gord\\Desktop\\foo.accdb;’; $dbh = new PDO($connStr); $dbh->setAttribute(PDO::ATTR_ERRMODE, … Read more