RSS

Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0×80004005

Check if the RetainSameConnection Option is set to true or false for your Database Connection.
I was attempting to Update data by using a Data Flow Transformation
OLE DB Source –> OLE DB Command

When the RetainSameConnection was set to TRUE, I encountered errors.
When the RetainSameConnection was set to FALSE, the package functions as expected.
Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0×80004005.
An OLE DB record is available. Source: “Microsoft SQL Server Native Client 10.0″ Hresult: 0×80004005 Description: “Syntax error, permission violation, or other nonspecific error”.

http://connect.microsoft.com/SQLServer/feedback/details/682902/ssis-failing-pre-execution-when-retainsameconnection-is-set-to-true

 

 

 
Leave a comment

Posted by on November 10, 2011 in Uncategorized

 

Tags: , ,

ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

Did you create a DSN, but your application cannot access the DSN?

I created a DSN, but could not connect via SSIS. It seems that the DSN I created was 32-bit, while the application I was using (SSIS) could only connect to 64-bit DSNs.

After some research I have realized that there are two different ODBC Administrator runtimes on a 64-bit machine. The first ODBC Manager is used to manage 32-bit data sources, while the second is used to manage 64-bit data sources.

Use this ODBC Manager to Review 32 Bit Data Source Names

c:\windows\system32\odbcad32.exe

Use this ODBC Manager to Review 64 Bit Data Source Names

c:\windows\sysWOW64\odbcad32.exe

If you are trying to access a DSN in your application and receive the error “ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application” check to see if you have a DSN configured for the architecture of your application ( 32-bit / 64-bit ).

I create my DSNs twice – once for 32 bit architecture and once for 64 bit architecture. My naming convention is as follows:

  • DSN_NAME created using c:\windows\system32\odbcad32.exe
  • DSN_NAME_64 created using c:\windows\sysWOW64\odbcad32.exe
Good Luck
 
1 Comment

Posted by on October 27, 2011 in Uncategorized

 

Tags: , , , , , , ,

restore database and automatically drop database snapshot transact sql

To facilitate quick testing of changes on my development and test environments I leverage database snapshots greatly.  The benefit of snapshots is that I can revert data to its previous state without having testers wait 30 – 40 minutes to perform another database restore, only to repeat tests again. Also, I can do a join on the data in the snapshot database, to compare data.

Snapshots are a great help. However, I still need to refresh the source database every now and then from the production source to get up to date data. The following methodology allows me to drop all existing snapshots and restore database in one step, without having to do a lot of work manually checking for snapshots, then dropping each one individually, then performing my restore.

Once I have the script define for a database I put in svn so that my entire team has access to the script and can restore a database unattended.

e.g. http://svn/database/servername/database_restore_scripts/mydatabase.sql

Please note however that

  1. If you run this script you drop and lose all your snapshots on a database permanently.
  2. If you do not have backups of your test databases, make sure that all your users are ok with you refreshing the environment before doing your data refresh from production.

My process is to

  1. drop any existing database snapshots
  2. offline the database
  3. online the database
  4. restore the database
  5. fix users


-- DROP DATABASE SNAPSHOTS IF THEY EXIST
DECLARE @emailMessage NVARCHAR(4000)
DECLARE @database VARCHAR(100)
DECLARE @sql NVARCHAR(4000)
DECLARE cur_db CURSOR
FOR
select name
from sys.databases
where source_database_id IN (select database_id from sys.databases where name LIKE 'MyDatabase')
ORDER BY create_date DESC
FOR READ ONLY
OPEN cur_db
FETCH NEXT FROM cur_db INTO @database
WHILE (@@FETCH_STATUS = 0 )
BEGIN

SET @sql = 'ALTER DATABASE ['+@database+'] SET OFFLINE WITH ROLLBACK IMMEDIATE;'
EXEC sp_executesql @sql
SET @sql = 'ALTER DATABASE ['+@database+'] SET ONLINE;'
EXEC sp_executesql @sql
SET @sql = 'DROP DATABASE ['+@database+'];'
-- PRINT @sql
EXEC sp_executesql @sql
FETCH NEXT FROM cur_db INTO @database
END
CLOSE cur_db
DEALLOCATE cur_db
GO
-- OFFLINE THE MAIN DATABASE TO FORCE USERS OFF SYSTEM
ALTER DATABASE  [MyDatabase] SET OFFLINE WITH ROLLBACK IMMEDIATE;
GO
-- ONLINE THE DATABASE
ALTER DATABASE  [MyDatabase] SET ONLINE;
GO

-- BEGIN RESTORING DATABASE.
DECLARE @exitcode int, @sqlerrorcode int;
EXEC MASTER..sqlbackup N'-SQL "RESTORE DATABASE [MyDatabase]
FROM DISK=''\\BACKUP\MyDatabase.sqb''
WITH REPLACE
, DISCONNECT_EXISTING
, RECOVERY"', @exitcode OUTPUT, @sqlerrorcode OUTPUT;
IF (@exitcode <> 0) OR (@sqlerrorcode <> 0)
BEGIN
SET @emailMessage = 'FAILED DATABASE RESTORE | ' + @@SERVERNAME + ' | ' + SUSER_SNAME() + ' | '+ 'MyDatabase' + ' | ' + CONVERT(VARCHAR(20),getdate(),120)
EXEC msdb.dbo.sp_send_dbmail
@recipients='dbas@mydomain.com;',
@subject= @emailMessage,
@body= @emailMessage
END
ELSE
BEGIN
SET @emailMessage = 'SUCCESSFUL DATABASE RESTORE | ' + @@SERVERNAME + ' | ' + SUSER_SNAME() + ' | '+ 'MyDatabase' + ' | ' + CONVERT(VARCHAR(20),getdate(),120)
EXEC msdb.dbo.sp_send_dbmail
@recipients='dbas@mydomain.com;',
@subject= @emailMessage,
@body= @emailMessage
END
GO
-- RUN CODE TO RESOLVE MISMATCHED SIDS and USER ACCOUNTS WITH LOGINS
EXEC [MyDatabase].dbo.sp_fixusers
GO

 
Leave a comment

Posted by on September 2, 2011 in Uncategorized

 

Tags: , , , , , , , ,

how to find stored procedures in sql server 2008 or sql server 2005 across all databases

As much as I hate searching for objects or not having complete information to troubleshoot an issue sometimes I have to go search for a stored procedure / function in a database server.

To find which database contains a stored procedure I am looking for on a server I run the following script

-- SEARCH FOR OBJECT
-- FIND A ROUTINE / PROCEDURE / FUNCTION IN ALL DATABASES ON SERVER.
EXEC sp_msforeachdb N'USE [?];
SELECT
@@SERVERNAME + '' | '' + SUSER_SNAME() + '' | ''+ DB_NAME() + '' | '' + CONVERT(VARCHAR(20),getdate(),120) as [SOURCE],
ROUTINE_CATALOG, ROUTINE_SCHEMA, ROUTINE_NAME ,
''[''+ CAST(@@SERVERNAME AS VARCHAR(100))+ ''].[''+ ROUTINE_CATALOG + ''].[''+ ROUTINE_SCHEMA + ''].[''+ ROUTINE_NAME + '']'' as [FQN]
FROM [?].INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME LIKE ''%myROUTINEName%'';
'
GO

I combine this with registering a group of servers in management studio, and in one quick step I can search for a procedure or function in any set of servers and databases.

 

 
Leave a comment

Posted by on September 2, 2011 in database

 

Tags: , , , , , ,

sql server create or replace procedure

Oracle has great syntax to CREATE OR REPLACE a stored procedure.

When I have to sync up multiple servers or deploy a specific procedure across my entire SQL Server Environment, I like to have a single script which can create the procedure where it needs to be created, and alter the procedure if it needs to be altered.

To make my code runnable on a server that may / may not already have my stored procedure I create a code stub, then replace it with the correct code.

Here is an example of code I use for database backups with Red Gate

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME LIKE 'usp_BackupLogs' AND ROUTINE_TYPE LIKE 'PROCEDURE' )
BEGIN
EXEC sp_executesql N'CREATE PROCEDURE [dbo].[usp_BackupLogs] AS SELECT CONVERT(VARCHAR(20),getdate() ,120)  + '' - Code Stub to Be Replaced by Alter Script '' as [Stub]'
END
GO
ALTER PROCEDURE [dbo].[usp_BackupLogs]
AS
DECLARE @emailMessage NVARCHAR(4000)
DECLARE @exitcode int
DECLARE @sqlerrorcode int
EXEC MASTER..sqlbackup N'-SQL "BACKUP LOGS [*] TO DISK = ''\\BACKUPS\LOGS\'' WITH NAME = '''', DESCRIPTION = '''', INIT, PASSWORD = ''mypassword'', MAXDATABLOCK = 65536,KEYSIZE = 256, COMPRESSION = 1, THREADS = 1"', @exitcode OUTPUT, @sqlerrorcode OUTPUT
IF (@exitcode <>  0) OR (@sqlerrorcode <> 0)
BEGIN
SET @emailMessage = 'FAILED LOG BACKUP | ' + @@SERVERNAME + ' | ' + SUSER_SNAME() + ' | '+ DB_NAME() + ' | ' + CONVERT(VARCHAR(20),getdate(),120)
EXEC msdb.dbo.sp_send_dbmail
@recipients=N'DBAS@mydomain.com',
@importance = 'High',
@subject = @emailMessage,
@body= @emailMessage
END
-- COMMENTED OUT INTENTIONALLY - DO NOT WANT EMAILS ON SUCCESSFUL LOG BACKUPS (esp. if scheduled every 15 minutes/ frequently)
--ELSE
-- BEGIN
-- SET @emailMessage = 'SUCCESSFUL LOG BACKUP | ' + @@SERVERNAME + ' | ' + SUSER_SNAME() + ' | '+ DB_NAME() + ' | ' + CONVERT(VARCHAR(20),getdate(),120)
-- EXEC msdb.dbo.sp_send_dbmail
-- @recipients=N'DBAS@mydomain.com',
-- @subject = @emailMessage,
-- @body= @emailMessage ;
-- End

Following this example if I want to deploy all the code from a server to another machine, I generate the CREATE Statements using the following code:

This prevents the need for 2 separate scripts (CREATE AND ALTER).

----------------------------------------------------------------
-- CREATE OR REPLACE ALL STORED PROCEDURES
----------------------------------------------------------------
SELECT
ROUTINE_NAME
,'EXEC sp_executesql N'''+REPLACE(N'CREATE PROCEDURE ['+ROUTINE_SCHEMA+'].['+ROUTINE_NAME+'] AS SELECT CONVERT(VARCHAR(20),getdate() ,120) + '' - Code Stub to Be Replaced by Alter Script '' as [Stub]','''','''''') + '''' as cmd
FROM INFORMATION_SCHEMA.ROUTINES
WHERE
ROUTINE_TYPE LIKE 'PROCEDURE'
ORDER BY ROUTINE_NAME ASC

Subsequently I script all objects as ALTERS and append to the CREATE script.

I create a single Script File with the following convention
1. CREATE scripts (code stubs) ( with if not exists )
2. ALTER scripts (real code)

 
Leave a comment

Posted by on September 2, 2011 in database, sql

 

Tags: , , , , , , ,

How to Find a Table on a SQL Server across all Databases

As much as I hate searching for objects or not having complete information to troubleshoot an issue sometimes I have to go search for a table in the database.

To find which database contains a table I am looking for on a server I run the following script

-- SEARCH FOR OBJECT
-- FIND A TABLE IN ALL DATABASES ON SERVER.
EXEC sp_msforeachdb N'USE [?];
SELECT
@@SERVERNAME + '' | '' + SUSER_SNAME() + '' | ''+ DB_NAME() + '' | '' + CONVERT(VARCHAR(20),getdate(),120) as [SOURCE],
TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME ,
''[''+ CAST(@@SERVERNAME AS VARCHAR(100))+ ''].[''+ TABLE_CATALOG + ''].[''+ TABLE_SCHEMA + ''].[''+ TABLE_NAME + '']'' as [FQN]
FROM [?].INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE ''%mytableName%'';
'
GO

I combine this with registering a group of servers in management studio, and in one quick step I can search for a table in any set of servers and databases.

 

 
1 Comment

Posted by on August 24, 2011 in database, Uncategorized

 

Tags: , , , , ,

SSIS Change Text File Column Delimiter in Text Editor

Ever want to change delimiter in SSIS Package without needing to open up BIDS?

Quick Ctrl+H and change out

_x0009_ Represents Tab Character
_x007C_ Represents Vertical Bar Character
_x002C_ Represents Comma
Set Delimiter to TAB ( \t )
<DTS:Property DTS:Name=”ColumnDelimiter” xml:space=”preserve”>_x0009_</DTS:Property>
Set Delimiter to Vertical Bar ( | )
<DTS:Property DTS:Name=”ColumnDelimiter” xml:space=”preserve”>_x007C_</DTS:Property>
Set Delimiter to Comma ( , )
<DTS:Property DTS:Name=”ColumnDelimiter” xml:space=”preserve”>_x002C_</DTS:Property>

 
Leave a comment

Posted by on June 16, 2011 in Uncategorized

 

Tags: , ,

The file ‘myDatabase_LOG2′ cannot be removed because it is not empty. Server: Msg 5042, Level 16, State 2, Line 1

When doing some re-indexing on a server, I had to create an additional log file so that the disk drive would not fill up and stop the database / re-index operation.

Subsequent to doing my re-index, no matter how many times I attempted to do a dbcc shrinkfile with the emptyfile option, the file would not delete.

The file ‘Database_Log_File’ cannot be removed because it is not empty.


USE [myDatabase]
GO
-- EMPTY TRANSACTION LOG FILE
DBCC SHRINKFILE(myDatabase_LOG2,EMPTYFILE)
GO
-- TO CLEAR OUT TRANSACTION LOG FILE -- PERFORM A TRANSACTION LOG BACKUP - Standard SQL Backup

BACKUP LOG [myDatabase] TO DISK = '\\myBackupShare\myDatabase_yyyymmdd.trn',INIT, PASSWORD= 'myPasword';

-- TO CLEAR OUT TRANSACTION LOG FILE -- PERFORM A TRANSACTION LOG BACKUP - Red Gate
DECLARE @exitcode int
DECLARE @sqlerrorcode int
EXEC MASTER..sqlbackup N'-SQL "BACKUP LOG [myDatabase]
TO DISK = ''\\myBackupShare\''
WITH NAME = '''', DESCRIPTION = '''',
INIT, PASSWORD = ''myPasword''
, MAXDATABLOCK = 65536,KEYSIZE = 256, COMPRESSION = 1, THREADS = 1"'
, @exitcode OUTPUT, @sqlerrorcode OUTPUT
GO

-- REMOVE TRANSACTION LOG FILE
ALTER DATABASE [myDatabase] REMOVE FILE [myDatabase_LOG2]
GO

 
Leave a comment

Posted by on March 4, 2011 in administration, Uncategorized

 

Tags: , , , , , , , ,

Automatically Save Email Attachments following a naming convention

Have you ever have a client that will only send you data as Email attachments, no ftp, etc,… I had the same case, but did not have direct access to the exchange server and did not have the time to spend researching a sexier way to automatically download their attachments.

This can easily be enhanced to do only messages from specific senders, other folders, etc. However the following code is what I used to perform one click save of all files to a network share, which then could be picked up by SSIS.


Sub SaveOutlookFileAttachments()
Dim oStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oFolders As Outlook.Folders
Dim oFolder As Outlook.Folder
Dim destFolder As String
Dim oItems As Outlook.Items
Dim oMsg As Outlook.MailItem
Dim oAttachments As Outlook.Attachments
Dim oAttachment As Outlook.Attachment
Dim oExplorer As Outlook.Explorer
destFolder = "\\NetworkShare\OrderDetailReport\"

On Error Resume Next
Set oStores = Application.Session.Stores
For Each oStore In oStores
If oStore.DisplayName = "Inbox" Then
oFolders = oStore.GetSearchFolders
For Each oFolder In oFolders
oItems = oFolder.Items
For Each oMsg In oItems
oAttachments = oMsg.Attachments
For Each oAttachment In oAttachments
If InStr(1, oAttachment.FileName, "_orderdetailreport_", vbTextCompare) Then
'MsgBox ("This File Needs to be Saved: " & oAttachment.FileName)
oAttachment.SaveAsFile (destFolder & oAtch.DisplayName)
End If
Next
Next
Next
End If
Next
End Sub

 
2 Comments

Posted by on March 4, 2011 in business intelligence

 

Tags: , , ,

SSIS Error Code 0xC020209C & SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.

I encountered the above error when attempting to load a data file which contained the pipe character “|” as the delimiter when the tab character “\t” was expected.

This error message occurred when the two following error codes were encountered together:

  • Code: 0xC020209C
    Description: The column data for column “COLUMN NO 1″ overflowed the disk I/O
  • Code: 0xC0047038
    Description: Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component “Flat File Source” (1) returned error code 0xC0202091. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.

————————————————–
COLUMN DELIMITER WAS INCORRECT (“|”)
————————————————–

Microsoft (R) SQL Server Execute Package Utility
Version 10.0.2531.0 for 32-bit
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.

Started: 11:52:03 AM
Error: 2010-08-10 11:52:33.21
Code: 0xC020209C
Source: Load Data Flat File Source [1]
Description: The column data for column "COLUMN NO 1" overflowed the disk I/O buffer.
End Error
Error: 2010-08-10 11:52:33.21
Code: 0xC0202091
Source: Load Data Flat File Source [1]
Description: An error occurred while skipping data rows.
End Error
Error: 2010-08-10 11:52:33.21
Code: 0xC0047038
Source: Load Data SSIS.Pipeline
Description: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Flat File Source" (1) returned error code 0xC0202091. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.
End Error
DTExec: The package execution returned DTSER_FAILURE (1).
Started: 11:52:03 AM
Finished: 11:52:33 AM
Elapsed: 30.109 seconds

 
Leave a comment

Posted by on August 11, 2010 in Uncategorized

 
 
Follow

Get every new post delivered to your Inbox.