Hi,
My scenario is this:
I have a set of SQL commands coming from an OLE Source (bunch of records where each record is a SQL command).
These commands are received by a Script Component (within a Data Flow), which parses them and then needs to execute them on an MS Access file. The commands have a chance to fail, and I need to be able to log these errors but not fail the whole process (the
process should continue to the next command even if the previous command failed).
Any errors that occurred will be added to an Error Output and inserted in a log table.
Here's the snippet from my Script Component:
if (m_conn == null) { m_connMgr = this.Connections.Connection; m_conn = (IDbConnection)m_connMgr.AcquireConnection(null); } if (m_conn.State != ConnectionState.Open) m_conn.Open(); try { using (IDbCommand cmd = m_conn.CreateCommand()) { cmd.CommandText = newCommand.ToString(); ComponentMetaData.FireInformation(0, Variables.TaskName, "Executing...", "", 0, ref fireAgain); int rows = cmd.ExecuteNonQuery(); ComponentMetaData.FireProgress(rows.ToString() + " row(s) affected.", 0, 0, 0, Variables.TaskName, ref fireAgain); } } catch (Exception e1) { ComponentMetaData.FireProgress("Error Running Command: " + e1.Message, 0, 0, 0, Variables.TaskName, ref fireAgain); ErrorOutputBuffer.AddRow(); ErrorOutputBuffer.COMMAND = newCommand.ToString(); ErrorOutputBuffer.MESSAGE = e1.Message; ErrorOutputBuffer.TIMESTAMP = DateTime.Now; }
My MSAccess data source is OLEDB Provider "Microsoft Office 12.0 Access Database Engine".
When the script tries to connect to the Access file, the following exception occurs:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Data.IDbConnection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9BB226F4-2AF3-37E7-B91D-3BB936FC0A7E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).I also tried using a .NET provider for OLEDB, but then received the error message when trying to connect:
System.Data.OleDb.OleDbException: Cannot start your application. The workgroup information file is missing or opened exclusively by another user. at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)As you can see from the script, I'm using the IDbConnection interface because I had the same error with the OleDbConnection class, so I thought maybe I'd use the most generic interface possible (but it didn't help).
Also, obviously I'm the only one accessing the file so it shouldn't be open by another user.
I don't know how to proceed. Any help would be appreciated.
Thanks,
Eitan
Eitan Blumin; SQL Server Consultant - Madeira SQL Server Services; http://www.madeira.co.il/author/eitan/