Showing posts with label library. Show all posts
Showing posts with label library. Show all posts

Thursday, March 8, 2012

Add Parameters!

Please visit
http://msdn.microsoft.com/library/e...tegrity_topic05
& click the link 'Implementing Cascading Operations Using Stored
Procedures'. Please refer to the sub-topic titled 'Inserting a Row into
the Primary Table'. There are 2 scripts under this sub-topic. Both the
scripts create a stored procedure named usp_OrdersInsert. After the
second script, (which creates the procedure usp_OrdersInsert using
defaults), it is stated that:
---
If the default values for the columns had been expressions, such as a
system function like GETDATE(), this modification wouldn't have been so
simple, because a default value for a stored procedure's parameter can
only be a constant. In such a situation, you need to add parameters to
indicate that a default value is desired for a column and then issue
the INSERT using the DEFAULT keyword instead of using a specific value
for the column.
---
I couldn't exactly follow the last line in the above paragraph (which
starts with "In such a situation...."). Can someone explain me this
preferably with an example?
Sorry for the inconvenience caused in navigating to the article in the
above-mentioned URL.
Thanks,
ArpanLet's assume you want to execute a stored proc omitting one of its
parameters (thereby using the parameter default value, assuming it was
specified). If you want that parameter to be variable (such as the
SYSTEM_USER function) then you couldn't use the parameter default value
because a stored proc parameter can only be a constant.
The way you'd do it would be to define an additional parameter to the
proc to indicate this scenario (or perhaps use a special value for the
existing parameter, such as NULL, if you're sure it has no other meaning
in the context). The T-SQL in your proc would then check this
additional parameter and if it has a particular value it would execute
the INSERT statement slightly differently (using the DEFAULT keyword in
the insert statement).
Let me explain with an example...
create proc MyProc
(
@.Param1 int
@.Param2 varchar(128) = 'zzz'
)
as
insert into MyTable (col1, col2)
values (@.Param1, @.Param2)
go
exec MyProc @.Param1=7, @.Param2='abc'
exec MyProc @.Param1=8
OK, everything is fine. The 2nd call would use the value 'zzz' for
@.Param2 because we omitted that parameter when we called MyProc the 2nd
time. But what if we wanted a variable value for @.Param2 instead of
'zzz', like the result of the SYSTEM_USER function for instance? The
proc would look like:
create proc MyProc
(
@.Param1 int
@.Param2 varchar(128) = SYSTEM_USER
)
as
insert into MyTable (col1, col2)
values (@.Param1, @.Param2)
go
But that's invalid syntax! The proc won't even compile. There are a
couple ways to get around that. They both require that the default
value be specified at the table constraint level, so that the DDL for
MyTable looks like:
create table MyTable
(
col1 int,
col2 varchar(128) *DEFAULT SYSTEM_USER*
)
Then you could either use a special value (eg. NULL) for @.Param2 like this:
create proc MyProc
(
@.Param1 int,
@.Param2 varchar(128) = null
)
as
if (@.Param2 is null)
insert into MyTable (col1, col2)
values (@.Param1, *DEFAULT*) -- Use the table default for col2
else
insert into MyTable (col1, col2)
values (@.Param1, @.Param2)
go
which would force SQL Server to use the default defined at the table
constraint level when the insert statement was called. Alternately, if
NULL was a valid value that you wanted to allow for @.Param2, you could
have a 3rd parameter to the proc that would represent this condition,
like this:
create proc MyProc
(
@.Param1 int,
@.Param2 varchar(128) = null,
@.UseDefaultValue bit = 0
)
as
if (@.UseDefaultValue = 1)
insert into MyTable (col1, col2)
values (@.Param1, *DEFAULT*) -- Use the table default for col2
else
insert into MyTable (col1, col2)
values (@.Param1, @.Param2)
go
This would do the same as in the previous schema for MyProc except that
it would also allow MyTable.col2 to be NULL. For example
exec MyProc @.Param1=7, @.Param2='abc' -- MyTable.col2 would be 'abc'
exec MyProc @.Param1=8 -- MyTable.col2 would be NULL
exec MyProc @.Param1=9, @.UseDefaultValue=1 -- MyTable.col2 would be
the result of the SYSTEM_USER function
I hope this make it a little clearer and that I haven't just
you even more.
*mike hodgson*
blog: http://sqlnerd.blogspot.com
Arpan wrote:

>Please visit
>http://msdn.microsoft.com/library/e...tegrity_topic05
>& click the link 'Implementing Cascading Operations Using Stored
>Procedures'. Please refer to the sub-topic titled 'Inserting a Row into
>the Primary Table'. There are 2 scripts under this sub-topic. Both the
>scripts create a stored procedure named usp_OrdersInsert. After the
>second script, (which creates the procedure usp_OrdersInsert using
>defaults), it is stated that:
>---
>If the default values for the columns had been expressions, such as a
>system function like GETDATE(), this modification wouldn't have been so
>simple, because a default value for a stored procedure's parameter can
>only be a constant. In such a situation, you need to add parameters to
>indicate that a default value is desired for a column and then issue
>the INSERT using the DEFAULT keyword instead of using a specific value
>for the column.
>---
>I couldn't exactly follow the last line in the above paragraph (which
>starts with "In such a situation...."). Can someone explain me this
>preferably with an example?
>Sorry for the inconvenience caused in navigating to the article in the
>above-mentioned URL.
>Thanks,
>Arpan
>
>|||Thank you very much, Mike, for your input & for devoting your precious
time in helping me out. Your explanation with the appropriate examples
has really made things clearer. I doubt if anyone else could have
clarified my doubts in a better way.
Thanks once again,
Regards,
Arpan

Tuesday, March 6, 2012

Add linked server at Excel VBA

I had SQLDMO at reference library.

Private Sub test()
Dim s As SQLDMO.SQLServer
Dim ls As SQLDMO.LinkedServer
Set s = New SQLDMO.SQLServer
s.Connect "Server1", "ID", "Password"
Set ls = New SQLDMO.LinkedServer
With ls
.Name = "Server2"
.ProviderName = "SQLOLEDB"
.DataSource = "Server2"
' .ProviderString = ""

End With
s.LinkedServers.Add ls
s.Close

'End Sub

I block ProviderString as i don't know what is it.

I got an error message when it's running the line "s.LinkedServers.Add ls" that

"Run-time error '-2147206257 (80043b8f)':

Automation error"

My question:

1. What is providerstring? what should be put here?

2. How to fix the error

Hi there,

Provider string should look something like the following:

@.provstr=N'DRIVER={<driver name of your linked server, in this case Excel} ;SERVER=<address if your server where the driver resides>;DATABASE=<database name>; USER=<username>; PASSWORD=<password>; OPTION=3'

I found this here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=304918&SiteID=1

Also, this may help: http://www.databasejournal.com/features/mssql/article.php/10894_3085211_2

Since you're not executing within the QA of management studio, I'm guessing that you only need to put Excel's driver name in your provider string, but don't take my word as I haven't tried doing this in VB.

Hope this helps!

Isa

Thursday, February 16, 2012

add a reference in scriptComponent

I would like to use a custom build class library written in C# inside of the vb script. Does anyone know how to add the reference to the scriptComponent project once you open script through design script button?

By the way I am using visul studio 2005.

Thanks!

Jun,

You'll need to have your class assembly added to the GAC. Procedure here.

After that, you can add it by selecting the Project > Add Reference... in the opened script editor.

|||

That's not the only thing that you need to do. Read this:

VSA requires DLLs to be in the Microsoft.Net folder (but not all the time)

(http://blogs.conchango.com/jamiethomson/archive/2005/11/02/SSIS_3A00_-VSA-requires-DLLs-to-be-in-the-Microsoft.Net-folder-_2800_but-not-all-the-time_2900_.aspx)

-Jamie

|||It may also be valuable to point out that this same process can be used to call web services from script components/tasks as well (helpful for complete control over web service calls instead of using limited built in SSIS web service task). You can use wsdl.exe to create the proxy class then go through the same steps outlined above.|||

ADMariner wrote:

It may also be valuable to point out that this same process can be used to call web services from script components/tasks as well (helpful for complete control over web service calls instead of using limited built in SSIS web service task). You can use wsdl.exe to create the proxy class then go through the same steps outlined above.

And (in case anyone is still reading/interested Smile ) in Katmai you'll be able use Web References just as you can in Visual Studio today. So no need to even use WSDL.exe

-Jamie

|||Thanks a lot! I will try.|||

I installed my dll into GAC and also put it under .net directory. But when I add reference to my dll in ScriptCommponent project. Before adding any code , I could not save project anymore. It complained "Object reference not set to an instance of an object". Anyone know what I missing here?

Thanks!

|||

Jun Fan wrote:

I installed my dll into GAC and also put it under .net directory. But when I add reference to my dll in ScriptCommponent project. Before adding any code , I could not save project anymore. It complained "Object reference not set to an instance of an object". Anyone know what I missing here?

Thanks!

You don't actually have to save the project. Just closing down VSA will store all of the code within your script task/component.

Try just doing that and see if you still run into problems.

-Jamie

|||

Wow, it works without save project. I can't believe it. Thanks very very much!

I am new from java world to window world. Do you mind light me some more?

What I am trying to do is that taking input columns and using script to build a object that my webservice recogonized and serialized object and store serialized data to database. I used transformation type of scriptComponent, and added output column named serializedObject as Byte Stream type from ScriptComponent. In VB script serializedObject is byte[] , so I assign byte[] return from serializing object to it. But when I run intergation service I go error complain "The value is too large to fit in the column data area of the buffer."

Anybody have suggestion?

Thanks!

|||

Jun Fan wrote:

Wow, it works without save project. I can't believe it. Thanks very very much!

I am new from java world to window world. Do you mind light me some more?

What I am trying to do is that taking input columns and using script to build a object that my webservice recogonized and serialized object and store serialized data to database. I used transformation type of scriptComponent, and added output column named serializedObject as Byte Stream type from ScriptComponent. In VB script serializedObject is byte[] , so I assign byte[] return from serializing object to it. But when I run intergation service I go error complain "The value is too large to fit in the column data area of the buffer."

Anybody have suggestion?

Thanks!

The default length of the byte stream type (i.e. DT_BYTES) when you add a column of that type to the script component is 50. My guess is that the length of the value you are tryig to put in there is more than 50.

-Jamie