Check OLDEDB database Connection using script task in SSIS.

Gopinath Desai 46 Reputation points
2020-12-15T21:38:02.363+00:00

Hi all,
How can i check or test OLEDB connection in SSIS using script component before going to use the connection.
All i need is to check whether OLEDB connection is successful if "Yes" got next step if "No" then send mail or write to log table.

I went online but couldn't get right code or info since am not very good at C# or VB.
Please help me how to do this.

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,592 questions
0 comments No comments
{count} votes

Accepted answer
  1. Monalv-MSFT 5,901 Reputation points
    2020-12-16T06:28:21.427+00:00

    Hi @Gopinath Desai ,

    We can use the following C# code in Script Task to check the OLEDB Connection.
    48537-scripttask.png

    public void Main()  
    		{  
                try  
                {  
                    ConnectionManager myOLEDBConnection1 = Dts.Connections["Test OLEDB Connection1"];  
                    MessageBox.Show(myOLEDBConnection1.ConnectionString, "Test OLEDB Connection1 Successfully!");  
                    Dts.Variables["Result"].Value = 1;  
                }  
                catch (Exception ex)  
                {  
                    Debug.WriteLine("Exception Message: " + ex.Message);  
                    MessageBox.Show("Exception Message: " + ex.Message);  
                    Dts.Variables["Result"].Value = 0;  
                }  
      
                Dts.TaskResult = (int)ScriptResults.Success;  
    		}  
    

    Please refer to Connecting to Data Sources in the Script Task.

    Best Regards,
    Mona

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues in November--What can I do if my transaction log is full?
    Hot issues in November--How to convert Profiler trace into a SQL Server table?


1 additional answer

Sort by: Most helpful
  1. Yitzhak Khabinsky 25,956 Reputation points
    2020-12-17T04:39:37.77+00:00

    It is relatively easy to implement a connection testing by calling the AcquireConnection() method of a connection manager.

    Here is the link to the official documentation: connecting-to-data-sources-in-the-script-task

    And obviously never use MessageBoxes in the production code.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.