Check if a SQL table exists

bool exists; try { // ANSI SQL way. Works in PostgreSQL, MSSQL, MySQL. var cmd = new OdbcCommand( “select case when exists((select * from information_schema.tables where table_name=”” + tableName + “”)) then 1 else 0 end”); exists = (int)cmd.ExecuteScalar() == 1; } catch { try { // Other RDBMS. Graceful degradation exists = true; var … Read more

Determine real cause of ODBC failure (error 3146) with ms-access?

Use the DbEngine.Errors collection. Sub Update_Temp() On Error GoTo ErrorTrap ‘ Execute connect code at this point Exit_errortrap: Exit Sub ErrorTrap: Dim myerror As DAO.Error For Each myerror In DBEngine.Errors With myerror If .Number <> 3146 Then MsgBox .Description End If End With Next Resume Exit_errortrap End Sub To enable this code, make sure in … Read more

How to increase performance for bulk INSERTs to ODBC linked tables in Access?

This situation is not uncommon when dealing with bulk INSERTs to ODBC linked tables in Access. In the case of the following Access query INSERT INTO METER_DATA (MPO_REFERENCE) SELECT MPO_REFERENCE FROM tblTempSmartSSP where [METER_DATA] is an ODBC linked table and [tblTempSmartSSP] is a local (native) Access table, the Access Database Engine is somewhat limited in … Read more

ERROR : [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

If you’re working with an x64 server, keep in mind that there are different ODBC settings for x86 and x64 applications. The “Data Sources (ODBC)” tool in the Administrative Tools list takes you to the x64 version. To view/edit the x86 ODBC settings, you’ll need to run that version of the tool manually: %windir%\SysWOW64\odbcad32.exe (%windir% … Read more

ASP.NET ODBC Query with parameters

From MSDN: When CommandType is set to Text, the .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder. For example: SELECT * FROM Customers WHERE CustomerID = ? … Read more

Save password for ODBC connection to MS SQL server from MS Access 2007

The best solution is obviously to use Windows security. If that is not suitable, here is a possible alternative trick, exploiting the fact that Access remembers all opened connections until the program is closed: copy the connect string of one of your tables create a passthru queries “ptqConnect” and enter any fast SQL statement in … Read more

PHP and Microsoft Access database – Connection and CRUD

PDO If you want to interface with an MS Access database using PHP, PDO is available for you. <?php try { $pdo = new PDO(“odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\accounts.mdb;Uid=Admin”); } catch (PDOException $e) { echo $e->getMessage(); } When using PDO, due to the unified interface for DB operations, you have the opportunity to make your app … Read more

Intermittent ODBC connection failures

I’ve had numerous issues with this in the past and the following worked: Navigate to Start | Microsoft SQL Server 2014 | SQL Server 2014 Configuration Manager. Expand SQL Server Network Configuration, then click on the 2008 instance. Upon doing that, on your right, you will notice Shared Memory, Named Pipes and TCP/IP. Open Named … Read more