Showing posts with label execute. Show all posts
Showing posts with label execute. Show all posts

Friday, March 30, 2012

Invokation of a stored procedure from an Integration Services package

Is it possible to execute a stored procedure from an Integration Services package? I see that its possible to enter sql commands that can be run but when a command to execute a stored procedure is entered the system cannot find the stored procedure (eventhough 'use mydbname' preceded it.

thx,

Marilyn

You certainly can execute a stored procedure, but we'll need some more information to help.

Are you using the Execute SQL task in SSIS? Is the database SQL Server? Does the account your are developing under have permissions to see the stored procedure? What error messages are you seeing?

Donald

Wednesday, March 28, 2012

Invalid XML Elements found inside cync block

I'm receiving the following error when attempting to execute an
updategram using SQL 2005 and SQLXML 4.0
FrostingModel.Tests.Artist.InvalidConcurrencyUpdate :
Microsoft.Data.SqlXml.SqlXmlException : HRESULT="0x80004005"
Description="Invalid XML elements found inside sync block"
Here is my updategram.
<u>
<updg:sync mapping-schema=".\Schemata\Artist.xsd" nullvalue="NULL"
xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:before>
<ns1:Artist updg:id="0" ArtistID="1716"
UpdateStamp="AAAAAAAADUw=" xmlns:ns1="urn:Frosting" />
</updg:before>
<updg:after>
<ns1:Artist updg:id="0" ArtistID="1716" Name="Blah Blah Update"
xmlns:ns1="urn:Frosting" />
</updg:after>
</updg:sync>
</u>
And here is the accompanying schema:
<xsd:complexType name="Artist">
<xsd:attribute name="ArtistID" type="xsd:int" use="required"
sql:identity="ignore" sql:datatype="int" />
<xsd:attribute name="Name" type="xsd:string" use="optional"
sql:datatype="nvarchar" />
<xsd:attribute name="UpdateStamp" use="optional" dt:type="bin.hex"
sql:datatype="timestamp" sql2:concurrency="UseValue" />
</xsd:complexType>
It should be noted that if I use concurrency on the Name attribute, it
works as expected. However I would prefer to use a timestamp - it's
the timestamp that seems to be the big proverbial pain in the arse.
I can't seem to find any solutions online regarding this problem... any
takers?
- ryan.Okay...
I changed my UpdateStamp value to be something like 0x000000000000101A
and the updategram worked as expected. However this doesn't make any
sense, because SQL 2005's FOR XML EXPLICIT returns the timestamp value
in a 12 character format such as "AAAAAAAADUw=", not in the above
format.
Am I missing something, or is this a bug in SQLXML 4.0 / SQL 2005? How
is it that SQL 2005 can emit a timestamp value in that "AAA..." format,
but it can't accept it? Do I have to do some type of conversion on my
client side after I receive the timestamp value from sql server?
Any help would be appreciated,
- cranley
cranley wrote:
> I'm receiving the following error when attempting to execute an
> updategram using SQL 2005 and SQLXML 4.0
> FrostingModel.Tests.Artist.InvalidConcurrencyUpdate :
> Microsoft.Data.SqlXml.SqlXmlException : HRESULT="0x80004005"
> Description="Invalid XML elements found inside sync block"
> Here is my updategram.
> <u>
> <updg:sync mapping-schema=".\Schemata\Artist.xsd" nullvalue="NULL"
> xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
> <updg:before>
> <ns1:Artist updg:id="0" ArtistID="1716"
> UpdateStamp="AAAAAAAADUw=" xmlns:ns1="urn:Frosting" />
> </updg:before>
> <updg:after>
> <ns1:Artist updg:id="0" ArtistID="1716" Name="Blah Blah Update"
> xmlns:ns1="urn:Frosting" />
> </updg:after>
> </updg:sync>
> </u>
> And here is the accompanying schema:
> <xsd:complexType name="Artist">
> <xsd:attribute name="ArtistID" type="xsd:int" use="required"
> sql:identity="ignore" sql:datatype="int" />
> <xsd:attribute name="Name" type="xsd:string" use="optional"
> sql:datatype="nvarchar" />
> <xsd:attribute name="UpdateStamp" use="optional" dt:type="bin.hex"
> sql:datatype="timestamp" sql2:concurrency="UseValue" />
> </xsd:complexType>
> It should be noted that if I use concurrency on the Name attribute, it
> works as expected. However I would prefer to use a timestamp - it's
> the timestamp that seems to be the big proverbial pain in the arse.
> I can't seem to find any solutions online regarding this problem... any
> takers?
> - ryan.

Invalid Use of Null

I am getting the "Invalid use of Null" message when I execute the following code under the following conditions.

fields in SQL Server table
db_date varchar(30) --> "December 29"
db_subject varchar(200) --> "Test Subject"
db_thought text --> "This is a test to see if this works"

I execute the following code from VB6

strText = "select * from db_table where db_date = 'December 29'"
ors.open strText, dbConnect
if not ors.eof then
if not isnull(ors("db_thought")) then
txtBox1 = ors("db_thought")
end if
end if

Here is my problem. Since there is a value in db_thought the code if not isnull(ors("db_thought")) evaluates to true -- this is what I expect. However when I try to assign the ors("db_thought") to the txBox1 field I get an Invalid use of Null. What am I missing?

ThanksWhat happens if you change the if statement to:

if isnull(...) then
txtField1 = ""
else
txtField1 = ...
end if

Also, put in a msgbox before the assignment to display the value or look at it in debug mode under locals.|||Originally posted by rnealejr
What happens if you change the if statement to:

if isnull(...) then
txtField1 = ""
else
txtField1 = ...
end if

Also, put in a msgbox before the assignment to display the value or look at it in debug mode under locals.

I tired your suggestion, and I get the same results. It appears that the test to see if there is information in the field is testing to be true, but the attempt to read from the field is saying that the information is null. I have rechecked the database to see if there is valid data in the field and I see data there.

Monday, March 26, 2012

Invalid Object Name?

Hi

I am developing a windows application that connects to a sql 2000 server. I have created a stored procedure and I am trying to execute the stored procedure in the query analyzer.

Here is the code for the stored procedure

CREATE PROCEDURE dbo.CountofComebacks
(
@.dlname as nvarchar(25),
@.CB as nvarchar(10)
)

AS

Select count([@.dlname].[Auditors working code])
from [@.dlname]
where [Auditors working code] = @.CB
GO

Here is the code that I am attempting to use in the query analyzer

Declare @.dlname as nvarchar(25)
set @.dlname = 'SWMC-OP-02-2005'
Declare @.CB as nvarchar(10)
set @.CB = 'CB'
Execute CountofComebacks @.dlname, @.CB

I get the following error in the query analyzer

Server: Msg 208, Level 16, State 1, Procedure CountofComebacks, Line 9
Invalid object name'@.dlname'.

Any assistance would be greatly appreciated.

thanks


CREATE PROCEDURE dbo.CountofComebacks
(
@.dlname as nvarchar(25),
@.CB as nvarchar(10)
)

AS

DECLARE @.sql varchar(1000)

SET @.sql = 'Select count([' + @.dlname + '].[Auditors working code])
from ' + @.dlname + 'where [Auditors working code] = ' + @.CB

EXEC(@.sql)
GO

If you want to know more about how this works google for Dynamic SQL. There are disadvantages in using this approach too. there are plenty of articles over the net that xplain about "Dynamic SQL".

|||

First let me say thank you for your response.

That being said I am still getting an error when attempting to execute the sp in the query analyzer.

Here is the code in the query analyzer

Declare @.dlname as nvarchar
Set @.dlname = 'SWMCOP022005'
Declare @.CB as nvarchar
Set @.CB = 'CB'
Declare @.NumberofCBs as integer
Execute CountofComebacks @.dlname, @.CB, @.NumberofCBs

Here is the sp

CREATE PROCEDURE dbo.CountofComebacks
(
@.dlname as nvarchar(25),
@.CB as nvarchar(10),
@.NumberofCBs as int
)

AS

DECLARE @.sql varchar(1000)

SET @.sql = 'Select count([' + @.dlname + '].[Auditors working code])
from ' + @.dlname + 'where [Auditors working code] = ' + @.CB

EXEC(@.sql)

return @.NumberofCBs
GO

and here is the error I receive in the query analyzer

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '='.
The 'CountofComebacks' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.

Is this because of the syntax error on line 2?

thanks

|||

throw in an ISNULL function.

SET @.sql = 'Select ISNULL(count([' + @.dlname + '].[Auditors working code]),0) from ' + @.dlname + 'where [Auditors working code] = ' + @.CB

sql

Invalid object name sysperfinfo

When I execute this statement through ASP.NET

select cntr_value FROM sysperfinfo


I get this error,

System.Data.SqlClient.SqlException: Invalid object name 'sysperfinfo'.

Any ideas why?

It sounds to me like your connectionstring (the string that points to the database which you are querying) is pointing to a database that does not have a table entitled 'sysperfinfo'|||

To add to the previous post some things have changes about sysperfinfo. Try the links below for more. Hope this helps.

sysperfinfo

In SQL Server 2005,sysperfinfo returns abigint value for thecntr_value column. Modify applications that usesysperfinfo to make sure that they can handle thebigint values of thecntr_value column.

In SQL Server 2005,sysperfinfo is a compatibility view. You should use thesys.dm_os_performance_counters dynamic management view instead.


http://msdn2.microsoft.com/en-us/library/ms143179.aspx


http://www.sqlservercentral.com/columnists/jsack/troubleshootingsqlserverwiththesysperfinfotable.asp

|||

Maybe you're in the wrong database, try:

select cntr_value FROM master..sysperfinfo

Invalid object name 'sysmergepublications' Please Help

Hi,
I'm trying to use Alternate Sync Partner.
I have found this how-to http://support.microsoft.com/kb/321176
but when I execute procedure ( step 9, my names are different )
sp_addmergealternatepublisher @.publisher = 'PublisherA'
, @.publisher_db = 'TestA'
, @.publication = 'DemoPublication'
, @.alternate_publisher = 'PublisherB'
, @.alternate_publisher_db = 'TestB'
, @.alternate_publication = 'DemoPublication'
, @.alternate_distributor = 'PublisherB'
I get this error
"Server: Msg 208, Level 16, State 1, Procedure
sp_addmergealternatepublisher, Line 38
Invalid object name 'sysmergepublications'."
What can be wrong? It is running on Sql Server 2000 SP 3a , replication
between PublisherA and PublisherB is OK.
Best Regards
Wojciech Znaniecki
Uytkownik "Wojtek Z" <wojtas_z@.poczta.fm> napisa w wiadomoci
news:csoa5s$bqe$1@.nemesis.news.tpi.pl...
> "Server: Msg 208, Level 16, State 1, Procedure
> sp_addmergealternatepublisher, Line 38
> Invalid object name 'sysmergepublications'."
Sorry
My mistake,
Before sp_addmergealterpublisher i should have exec
use [db_name]
GO
Now it is ok.
Wojciech Znaniecki

Monday, March 12, 2012

Invalid column name Ploeg.

When i try to execute i receive following error:

Msg 207, Level 16, State 1, Procedure WedstrijdDeelnemersSelectAllMPNietGoedgekeurd, Line 85

Invalid column name 'Ploeg'.

I dont really see whats wrong with the select... it works fine in the 2 first parts of the querry

ALTER PROCEDURE [dbo].[WedstrijdDeelnemersSelectAllMPNietGoedgekeurd]-- Add the parameters for the stored procedure here@.WedstrijdIDintASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;...UNIONSELECTdbo.fncGetPersoonNaam(L.PersoonID,0)as Persoon,'Ploeg: ' + WDPI.Ploegas TypeInschrijving,WDPIL.LidClubID,WT.Omschrijvingas WedstrijdType,C.Omschrijvingas Categorie,WDC.WedstrijdDetailID,WDC.IDas WedstrijdDetailCategorieID,WDPI.IDas TypeInschrijvingIDFROMWedstrijd WINNERJOIN WedstrijdDetail WDON W.ID = WD.WedstrijdIDINNERJOIN WedstrijdType WTON WD.WedstrijdTypeID = WT.IDINNERJOIN WedstrijdDetailCategorie WDCON WD.ID = WDC.WedstrijdDetailIDINNERJOIN Categorie CON WDC.CategorieID = C.IDINNERJOIN WedstrijdDetailPloegInschrijving WDPION WDC.ID = WDPI.WedstrijdDetailCategorieIDINNERJOIN WedstrijdDetailPloegInschrijvingLid WDPILON WDPIL.WedstrijdDetailPloegInschrijvingID = WDPI.ID...
END

forget it, someone updated the database and removed the column...Big Smile

Friday, March 9, 2012

Invalid Column Name

When I execute the following command under SQL Server 2000, "ALT_1_UNIT" is
correctly interpreted as the column name ALT_1_UNIT:
set quoted_identifier on
select "ALT_1_UNIT"
from IM_ITEM
However, I would like to be able to dynamically set the column name like
this:
set quoted_identifier on
declare @.UNIT varchar(1)
set @.UNIT = '1'
select "ALT_" + @.UNIT + "_UNIT"
from IM_ITEM
When I execute this command, I get the errors
Server: Msg 207, Level 16, State 3, Line 4
Invalid column name 'ALT_'.
Server: Msg 207, Level 16, State 1, Line 4
Invalid column name '_UNIT'.
From this, it appears that I cannot concatenate a column identifier and a
string.
I then tried replacing the single quotes in
set @.UNIT = '1'
with double quotes as in
set @.UNIT = "1"
That produced an additional error:
Server: Msg 207, Level 16, State 3, Line 3
Invalid column name '2'.
Server: Msg 207, Level 16, State 1, Line 4
Invalid column name 'ALT_'.
Server: Msg 207, Level 16, State 1, Line 4
Invalid column name '_UNIT'.
From this, it appears that I cannot store a column identifier in a variable.
How can I accomplish what I want to do?Paul,
I'm not sure what exactly you are trying to accomplish, however for what you
are attempting this should work fine in a stored procedure for sql 2k
CREATE PROCEDURE sp_testthis
(
@.Unit varchar(1)
)
AS
select "ALT_" + @.Unit + "_UNIT" as mystring
from
IM_ITEM
GO
mystring is what you will be selecting in code...for example (c#):
// ****************************************
**************
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=myserver;Initial
Catalog='mycatalogue';Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand("sp_testthis", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1= new SqlParameter("@.Unit", SqlDbType.VarChar,
1);
param1.Value = TextBox1.Text;
cmd.Parameters.Add(param1);
string mytest = String.Empty;
conn.Open();
SqlDataReader result =
cmd.ExecuteReader(CommandBehavior.CloseConnection);
result.Read();
mytest = (string)result["mystring"];
result.Close();
conn.Close();
cmd.Dispose();
Label1.Text = mytest.ToString();
}
// ****************************************
**************
HTH
"Paul D." <pablodados@.hotmail.com> wrote in message
news:XuAXf.71026$9I5.5222@.tornado.ohiordc.rr.com...
> When I execute the following command under SQL Server 2000, "ALT_1_UNIT"
> is
> correctly interpreted as the column name ALT_1_UNIT:
> set quoted_identifier on
> select "ALT_1_UNIT"
> from IM_ITEM
> However, I would like to be able to dynamically set the column name like
> this:
> set quoted_identifier on
> declare @.UNIT varchar(1)
> set @.UNIT = '1'
> select "ALT_" + @.UNIT + "_UNIT"
> from IM_ITEM
> When I execute this command, I get the errors
> Server: Msg 207, Level 16, State 3, Line 4
> Invalid column name 'ALT_'.
> Server: Msg 207, Level 16, State 1, Line 4
> Invalid column name '_UNIT'.
> From this, it appears that I cannot concatenate a column identifier and a
> string.
> I then tried replacing the single quotes in
> set @.UNIT = '1'
> with double quotes as in
> set @.UNIT = "1"
> That produced an additional error:
> Server: Msg 207, Level 16, State 3, Line 3
> Invalid column name '2'.
> Server: Msg 207, Level 16, State 1, Line 4
> Invalid column name 'ALT_'.
> Server: Msg 207, Level 16, State 1, Line 4
> Invalid column name '_UNIT'.
> From this, it appears that I cannot store a column identifier in a
> variable.
> How can I accomplish what I want to do?
>
>|||found a problem, this should work better
CREATE PROCEDURE sp_testthis
(
@.Unit varchar(1)
)
AS
declare @.mystring nvarchar(50)
select @.mystring = '
select ALT_' + @.Unit + '_UNIT
from
IM_ITEM'
execute(@.mystring)
GO
you will need to have select permission granted to your user on that table

> // ****************************************
**************
> protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=myserver;Initial
Catalog='mycatalogue';Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand("sp_testthis", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1 = new SqlParameter("@.Unit", SqlDbType.VarChar,
1);
param1.Value = TextBox1.Text;
cmd.Parameters.Add(param1);
string mytest = String.Empty;
try
{
conn.Open();
SqlDataReader result =
cmd.ExecuteReader(CommandBehavior.CloseConnection);
result.Read();
mytest = (string)result["Alt_" + TextBox1.Text + "_UNIT"];
result.Close();
conn.Close();
cmd.Dispose();
Label1.Text = mytest.ToString();
}
catch { Label1.Text = "error message"; }
}
> // ****************************************
**************
>
sorry, hope this works better|||That will work for me. Thanks!
Paul
"alice" <alice@.nospam.com> wrote in message
news:%234%233AtcVGHA.424@.TK2MSFTNGP12.phx.gbl...
> found a problem, this should work better
> CREATE PROCEDURE sp_testthis
> (
> @.Unit varchar(1)
> )
> AS
> declare @.mystring nvarchar(50)
> select @.mystring = '
> select ALT_' + @.Unit + '_UNIT
> from
> IM_ITEM'
> execute(@.mystring)
> GO
> you will need to have select permission granted to your user on that table
>
> {
> SqlConnection conn = new SqlConnection("server=myserver;Initial
> Catalog='mycatalogue';Integrated Security=SSPI");
> SqlCommand cmd = new SqlCommand("sp_testthis", conn);
> cmd.CommandType = CommandType.StoredProcedure;
> SqlParameter param1 = new SqlParameter("@.Unit", SqlDbType.VarChar,
> 1);
> param1.Value = TextBox1.Text;
> cmd.Parameters.Add(param1);
> string mytest = String.Empty;
> try
> {
> conn.Open();
> SqlDataReader result =
> cmd.ExecuteReader(CommandBehavior.CloseConnection);
> result.Read();
> mytest = (string)result["Alt_" + TextBox1.Text + "_UNIT"];
> result.Close();
> conn.Close();
> cmd.Dispose();
> Label1.Text = mytest.ToString();
> }
> catch { Label1.Text = "error message"; }
> }
> sorry, hope this works better
>|||Paul D. (pablodados@.hotmail.com) writes:
> When I execute the following command under SQL Server 2000, "ALT_1_UNIT"
> is correctly interpreted as the column name ALT_1_UNIT:
> set quoted_identifier on
> select "ALT_1_UNIT"
> from IM_ITEM
> However, I would like to be able to dynamically set the column name like
> this:
> set quoted_identifier on
> declare @.UNIT varchar(1)
> set @.UNIT = '1'
> select "ALT_" + @.UNIT + "_UNIT"
> from IM_ITEM
Sound like you have bad database design. You will need to use dynamic
SQL, which has a lot of consequences. I have an article on my web site
on dynamic SQL: http://www.sommarskog.se/dynamic_sql.html. Of particular
interest to you is http://www.sommarskog.se/dynamic_sql.html#Dyn_update.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns9799657D8C3FYazorman@.127.0.0.1...
> Paul D. (pablodados@.hotmail.com) writes:
> Sound like you have bad database design. You will need to use dynamic
> SQL, which has a lot of consequences. I have an article on my web site
> on dynamic SQL: http://www.sommarskog.se/dynamic_sql.html. Of particular
> interest to you is http://www.sommarskog.se/dynamic_sql.html#Dyn_update.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx
Thanks. I see your point about the database design being bad. This IM_ITEM
table includes columns ALT_1_UNIT through ALT_5_UNIT and those could be put
into a separate table. Unfortunately, I have no control over the design of
this particular database.
I do also see that I could use a case statement to determine the name of the
column based on the value of @.UNIT. Is there an advantage to doing it that
way as opposed to forming the column name through concatenation?
Paul D.|||Paul D. (pablodados@.hotmail.com) writes:
> I do also see that I could use a case statement to determine the name of
> the column based on the value of @.UNIT. Is there an advantage to doing
> it that way as opposed to forming the column name through
> concatenation?
Instead of getting five plans in the cache, you get one. Furthermore,
if you use dynamic SQL, but you neglect to prefix the table name with
"dbo.", each user will get his own plan. These are issue that you
avoid if you use stored procedures with static SQL.
And of course, if the users do not have SELECT permissions on the table,
there is a very important difference.
Overall, it's better to use a solution with static SQL when this is
possible, as it reduces complexity and thus reduces maintenance costs.
There are some exceptions to this rule, the prime example is dynamic
search conditions. Had you had 550 such columns, I might have advocated
a solution with dynamic SQL, but for five columns, no. Use CASE instead.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx