dbTalk Databases Forums  

Connecting to the database via an OLEDB connection manager within a script task

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Connecting to the database via an OLEDB connection manager within a script task in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John Hardin
 
Posts: n/a

Default Connecting to the database via an OLEDB connection manager within a script task - 09-19-2006 , 06:01 PM






Folks:

We have the need to write a lot of SSIS script tasks that talk directly to
the database. We use OLEDB connections, and log into the database using
database users rather than Windows integrated security.

Within a script task I'm able to create a new OLEDB connection object using
the connection string pulled from the connection manager, but as we are
using database passwords rather than Windows integrated security, and as the
package strips the password out of the connection string, I need to provide
a password. Where do we get the database password that the existing
connection is using?

Alternatively, how would you ask the OLEDB database connection manager to
provide a connection object? The tasks that SSIS provides have to get a
connection from the connection manager - how do *they* do it?

We'd rather not use an ADO.NET:OLEDB connection manager because Slowly
Changing Dimension tasks require a native OLEDB connection manager, and
having both an ADO.NET:OLEDB and a native OLEDB connection manager for the
same database forces having to enter the same configuration information in
two places, exposes the risk that they will be configured differently, and
makes us look stupid.

Can anybody suggest an elegant way to do this?

Thanks.

--
John Hardin KA7OHZ
Senior Applications Developer, RetailCRM Development
web: http://www.epicor.com
voice: (425) 672-1304
fax: (425) 672-0192
email: <jhardin (AT) epicor (DOT) com>
EPICOR|CRS Retail Solutions Division
3400 188th Street SW, Suite 185
Lynnwood, WA 98037 USA
Worldwide Headquarters 18200 Von Karman, Suite 1000, Irvine CA 92612 USA
------------------------------------------------------------------------
The first time I saw a bagpipe, I thought the player was torturing an
octopus. I was amazed they could scream so loudly.
------------------------------------------------------------------------


Reply With Quote
  #2  
Old   
John Hardin
 
Posts: n/a

Default Re: Connecting to the database via an OLEDB connection manager within a script task - 09-21-2006 , 11:33 AM






"kiran" <kiran.gazz (AT) gmail (DOT) com> wrote:
Quote:
hi John,
The soln is given below.
------------------------------------------------------------------------------
" Public Sub Main()

Dim vs As Variables
Dts.VariableDispenser.LockForRead("g_str_server")
Dts.VariableDispenser.LockForRead("g_str_username" )
Dts.VariableDispenser.LockForRead("g_str_password" )
Dts.VariableDispenser.LockForRead("g_str_databasen ame")
Dts.VariableDispenser.LockForRead("g_str_connectio ntype")
Dts.VariableDispenser.GetVariables(vs)
Dts.Connections("MD").ConnectionString = "Data Source=" &
vs("g_str_server").Value.ToString() & ";User ID=" &
vs("g_str_username").Value.ToString() & ";Pwd=" &
vs("g_str_password").Value.ToString() & ";Initial Catalog=" &
vs("g_str_databasename").Value.ToString() & ";Provider=SQLNCLI.1;Auto
Translate=False;"
Dts.Connections("MD").AcquireConnection(Nothing)
Dts.TaskResult = Dts.Results.Success
End Sub

--- NOTE :
2> Create the OLE DB Cnnection In conn manager (HEre I have named it ad
MD for that OLEDB Conn) .
1> Variables prifixed with "g_" are global variables and MD in
"Dts.Connections("MD")" is the name of the OLEDB Connection manager
Defined by the developer in Connection managers.
I think you interpreted the reverse of what I was asking. It appears from
the above that you are configuring an existing connection manager from
connection settings in package variables.

What I need is this: The package already has an OLEDB connection manager
(not necessarily talking to SQL Server!) that is configured via the standard
SSIS XML configuration file mechanism, and works for all of the non-script
tasks that interact with the database (e.g. an OLEDB query task).

What I need is to be able to look at that connection manager from within a
script task, and create a connection that talks to the same database so that
the script task can perform database operations.

I don't want to take the connection configuration information from package
variables. That's the hack I'm using right now, and I'd like something more
elegant, if possible.

Unfortunately, looking at the connection manager's ConnectionString property
isn't going to work as the database password is stripped off it.

Also unfortunately, according to the documentation AcquireConnection() does
not work at all for OLEDB connection managers, only ADO.NET connection
managers. How are you getting it to work in your example? (Remember to
distinguish between an OLEDB connection manager and an ADO.NET connection
manager that happens to be talking to an OLEDB data source...)

And that code looks like scripting for a control flow script task. The Dts
object doesn't exists in data flow script tasks, and that's where I need to
do this. Sorry for not making that clear in my initial post.

Thanks for your suggestion, though!

--
John Hardin KA7OHZ
Senior Applications Developer, RetailCRM Development
web: http://www.epicor.com
voice: (425) 672-1304
fax: (425) 672-0192
email: <jhardin (AT) epicor (DOT) com>
EPICOR|CRS Retail Solutions Division
3400 188th Street SW, Suite 185
Lynnwood, WA 98037 USA
Worldwide Headquarters 18200 Von Karman, Suite 1000, Irvine CA 92612 USA
------------------------------------------------------------------------
The first time I saw a bagpipe, I thought the player was torturing an
octopus. I was amazed they could scream so loudly.
------------------------------------------------------------------------



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.