Showing posts with label particular. Show all posts
Showing posts with label particular. Show all posts

Wednesday, March 28, 2012

Script Transform

Hi,

My requirement is to check whether value of a particular column is null or not. if it is null I have to enter warning messages into the temp table I have created.

For this I am using Script Transform

Now I want to know how to write info from script transform to a table using SSIS.

Currently I am using the following code in script component

[Code]

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Dim ConnString As String

ConnString = "Data Source=ABC;Initial Catalog=XXXX;Integrated Security=SSPI;"

Dim sqcn As New SqlConnection(ConnString)

''Dim sqlCmd As New SqlCommand(ConnString, sqcn)

'sqcn.Open()

if Row.Col1_IsNull Then

sqlCmd.CommandText = "Insert into AuditLog values('ERROR','Missing','" + Row.Col5 + "','" + Row.Col6 + "') "

sqlCmd.ExecuteNonQuery()

end if

End Sub

[/Code]

Without using SqlConnection and SqlCommand is thereany way I can get the Connection Obj and able to insert rec in the table.

Thanks

You can create ADO.NET Connection Manager object in the package, get it in script transfrom, and the AquireConnection method returns the managed connection object.

But why do you need script transform at all? You can use conditional split transform to find rows with missing column, and direct the output of conditional split transform to Sql Server or OLEDB Destination.

Script to stop a SQL service

Is there a script that I can run to stop a particular SQL server service on
Win2003 server? I'm looking for a similar script to restart that service as
well. Thanks.NET START <service>
NET STOP <service
If you have a default instance install of SQL Server 200: "NET START
MSSQLSERVER"

Regards
----------
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland

IM: mike@.epprecht.net

MVP Program: http://www.microsoft.com/mvp

Blog: http://www.msmvps.com/epprecht/

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
> Is there a script that I can run to stop a particular SQL server service
> on Win2003 server? I'm looking for a similar script to restart that
> service as well. Thanks.|||You can use the NET STOP and NET START commands from the command-prompt to
stop/start any Windows service. For a default SQL Server instance:

NET STOP MSSQLSERVER
NET START MSSQLSERVER

For a named instance:

NET STOP MSSQL$MyInstance
NET START MSSQL$MyInstance

You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
Examples:

'stop example
Option Explicit
Dim oSQLServer
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.Name = "MyServer"
oSQLServer.Stop

'start example
Option Explicit
Dim oSQLServer
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.Start False, "MyServer"

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
> Is there a script that I can run to stop a particular SQL server service
> on Win2003 server? I'm looking for a similar script to restart that
> service as well. Thanks.|||Would the syntax be the same if I ran the command line script from within a
batch file?

I'm planning on running this batch file from within the BackUp Exec
software. I have two database programs that run SQL services, preventing
the backup jobs from doing a thorough job. Automatically shutting down
those SQL services will allow jobs to complete properly.

"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
> You can use the NET STOP and NET START commands from the command-prompt to
> stop/start any Windows service. For a default SQL Server instance:
> NET STOP MSSQLSERVER
> NET START MSSQLSERVER
> For a named instance:
> NET STOP MSSQL$MyInstance
> NET START MSSQL$MyInstance
> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
> Examples:
> 'stop example
> Option Explicit
> Dim oSQLServer
> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
> oSQLServer.Name = "MyServer"
> oSQLServer.Stop
> 'start example
> Option Explicit
> Dim oSQLServer
> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
> oSQLServer.Start False, "MyServer"
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>> Is there a script that I can run to stop a particular SQL server service
>> on Win2003 server? I'm looking for a similar script to restart that
>> service as well. Thanks.
>>
>>|||> Would the syntax be the same if I ran the command line script from within
> a batch file?

Yes.

> I'm planning on running this batch file from within the BackUp Exec
> software. I have two database programs that run SQL services, preventing
> the backup jobs from doing a thorough job. Automatically shutting down
> those SQL services will allow jobs to complete properly.

Rather than cold backups, consider backing up your databases to disk using
Transact-SQL BACKUP DATABASE and then archiving the disk backup files to
tape using your backup software. This allows you to perform backups while
the databases are online and uses less tape storage. Many backup vendors
also provide a specialized backup agent for SQL Server that allows you to
backup SQL Server databases online.

In any case, be sure to thoroughly test your recovery procedure.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:Y_-dncZAa9tM3lbfRVn-hQ@.comcast.com...
> Would the syntax be the same if I ran the command line script from within
> a batch file?
> I'm planning on running this batch file from within the BackUp Exec
> software. I have two database programs that run SQL services, preventing
> the backup jobs from doing a thorough job. Automatically shutting down
> those SQL services will allow jobs to complete properly.
>
> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
> news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
>> You can use the NET STOP and NET START commands from the command-prompt
>> to stop/start any Windows service. For a default SQL Server instance:
>>
>> NET STOP MSSQLSERVER
>> NET START MSSQLSERVER
>>
>> For a named instance:
>>
>> NET STOP MSSQL$MyInstance
>> NET START MSSQL$MyInstance
>>
>> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
>> Examples:
>>
>> 'stop example
>> Option Explicit
>> Dim oSQLServer
>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>> oSQLServer.Name = "MyServer"
>> oSQLServer.Stop
>>
>> 'start example
>> Option Explicit
>> Dim oSQLServer
>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>> oSQLServer.Start False, "MyServer"
>>
>> --
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
>> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>>> Is there a script that I can run to stop a particular SQL server service
>>> on Win2003 server? I'm looking for a similar script to restart that
>>> service as well. Thanks.
>>>
>>>
>>
>>|||Thanks, guys. I'll give it a shot.

"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:zOQye.2686$vT3.2657@.newssvr30.news.prodigy.co m...
>> Would the syntax be the same if I ran the command line script from within
>> a batch file?
> Yes.
>> I'm planning on running this batch file from within the BackUp Exec
>> software. I have two database programs that run SQL services, preventing
>> the backup jobs from doing a thorough job. Automatically shutting down
>> those SQL services will allow jobs to complete properly.
> Rather than cold backups, consider backing up your databases to disk using
> Transact-SQL BACKUP DATABASE and then archiving the disk backup files to
> tape using your backup software. This allows you to perform backups while
> the databases are online and uses less tape storage. Many backup vendors
> also provide a specialized backup agent for SQL Server that allows you to
> backup SQL Server databases online.
> In any case, be sure to thoroughly test your recovery procedure.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
> news:Y_-dncZAa9tM3lbfRVn-hQ@.comcast.com...
>> Would the syntax be the same if I ran the command line script from within
>> a batch file?
>>
>> I'm planning on running this batch file from within the BackUp Exec
>> software. I have two database programs that run SQL services, preventing
>> the backup jobs from doing a thorough job. Automatically shutting down
>> those SQL services will allow jobs to complete properly.
>>
>>
>> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
>> news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
>>> You can use the NET STOP and NET START commands from the command-prompt
>>> to stop/start any Windows service. For a default SQL Server instance:
>>>
>>> NET STOP MSSQLSERVER
>>> NET START MSSQLSERVER
>>>
>>> For a named instance:
>>>
>>> NET STOP MSSQL$MyInstance
>>> NET START MSSQL$MyInstance
>>>
>>> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
>>> Examples:
>>>
>>> 'stop example
>>> Option Explicit
>>> Dim oSQLServer
>>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>>> oSQLServer.Name = "MyServer"
>>> oSQLServer.Stop
>>>
>>> 'start example
>>> Option Explicit
>>> Dim oSQLServer
>>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>>> oSQLServer.Start False, "MyServer"
>>>
>>> --
>>> Hope this helps.
>>>
>>> Dan Guzman
>>> SQL Server MVP
>>>
>>> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
>>> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>>>> Is there a script that I can run to stop a particular SQL server
>>>> service on Win2003 server? I'm looking for a similar script to restart
>>>> that service as well. Thanks.
>>>>
>>>>
>>>
>>>
>>
>>

Friday, March 9, 2012

Script component, dumb question

How do you tell the script task NOT to write a particular row?

This code currently writes 0 and blank when the type <> 4, i'm looking NOT to write the row at all.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
Inherits UserComponent

Private iType, iRest As String
Private rawAmount As Double

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
iType = Row.Type
iRest = Row.rest
If iType = "4" Then
Row.ani = iRest.Substring(112, 10)
rawAmount = CInt(iRest.Substring(41, 4))
If rawAmount <> 0 Then
Row.amount = rawAmount / 100
End If
End If
End Sub

End Class

Also, I'm writting these columns to a destination excel, and event hough the spreadsheet cells are formated for an nn.nn numeric, every cell has an error that my data is text and I get that green wedge asking me to convert it. If I manually enter what I'm sending(example 45.5, it takes it just fine and turns it into 45.50 numeric). What can I do about this? anything additional I can send excel to tell it treat numerics like numerics.. maybe something like: mso-number-format or something.

Thanks for any help or information.To have a script task not write a particular row, create two outputs, and direct desired rows to one output, undesired rows to the other.

By default, for a given script component, a single output is created. So, create a second output, named "Output 1" by default. Ensure the SynchrousInputID property of the new output is equal to that of the original. Set the ExclusionGroup on both outputs to 1, meaning they are filtered outputs.

In the component, direct rows as needed, connecting the desired output to downstream inputs. Unconnected ouputs are effectvely discarded (technically they are accessible on the disregarded output). Some will naturally reply, you can do similar operations with a conditional split, and that's true enough.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain

Inherits UserComponent

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

If True Then

Row.DirectRowToOutput0()

Else

Row.DirectRowToOutput1()

End If

End Sub

End Class

|||

Having problems with this. I have a script component in a data flow.

when I add the additional output, the synchronousInput id defaults to 0, and I can't change it to 1133 which is what Output 0 has.

In the code, when I attempt to add code like this

Row.DirectRowToOutput1()Row.DirectRowToOutput1()

property DirectRow* is not available. I must be missing something.

Also, while on this, how does one insert additional rows?

|||

You can't insert new rows into a synchronous output, only into an asynchronous one.

If the script component is set to be a transform (you're prompted for this when you first add the script component), then when you add the new output, the SynchronousInputID should be a dropdown that allows you to select the Input.

|||

re "property DirectRow* is not available. I must be missing something."

I had this problem too - resolved it by setting Exclusion Group from 0 to 1 on both outputs

Script component, dumb question

How do you tell the script task NOT to write a particular row?

This code currently writes 0 and blank when the type <> 4, i'm looking NOT to write the row at all.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
Inherits UserComponent

Private iType, iRest As String
Private rawAmount As Double

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
iType = Row.Type
iRest = Row.rest
If iType = "4" Then
Row.ani = iRest.Substring(112, 10)
rawAmount = CInt(iRest.Substring(41, 4))
If rawAmount <> 0 Then
Row.amount = rawAmount / 100
End If
End If
End Sub

End Class

Also, I'm writting these columns to a destination excel, and event hough the spreadsheet cells are formated for an nn.nn numeric, every cell has an error that my data is text and I get that green wedge asking me to convert it. If I manually enter what I'm sending(example 45.5, it takes it just fine and turns it into 45.50 numeric). What can I do about this? anything additional I can send excel to tell it treat numerics like numerics.. maybe something like: mso-number-format or something.

Thanks for any help or information.

To have a script task not write a particular row, create two outputs, and direct desired rows to one output, undesired rows to the other.

By default, for a given script component, a single output is created. So, create a second output, named "Output 1" by default. Ensure the SynchrousInputID property of the new output is equal to that of the original. Set the ExclusionGroup on both outputs to 1, meaning they are filtered outputs.

In the component, direct rows as needed, connecting the desired output to downstream inputs. Unconnected ouputs are effectvely discarded (technically they are accessible on the disregarded output). Some will naturally reply, you can do similar operations with a conditional split, and that's true enough.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain

Inherits UserComponent

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

If True Then

Row.DirectRowToOutput0()

Else

Row.DirectRowToOutput1()

End If

End Sub

End Class

|||

Having problems with this. I have a script component in a data flow.

when I add the additional output, the synchronousInput id defaults to 0, and I can't change it to 1133 which is what Output 0 has.

In the code, when I attempt to add code like this

Row.DirectRowToOutput1()Row.DirectRowToOutput1()

property DirectRow* is not available. I must be missing something.

Also, while on this, how does one insert additional rows?

|||

You can't insert new rows into a synchronous output, only into an asynchronous one.

If the script component is set to be a transform (you're prompted for this when you first add the script component), then when you add the new output, the SynchronousInputID should be a dropdown that allows you to select the Input.

|||

re "property DirectRow* is not available. I must be missing something."

I had this problem too - resolved it by setting Exclusion Group from 0 to 1 on both outputs