Wednesday, March 28, 2012
No formulas in Stored Procedure params?
is there any reason why it is not allowed to use formulas as Stored
Procedure parameters?
e.g.: EXEC myProc(@.myVar + ' ' + @.myVar2)
I could make use of this feature over and over if SQL Server 2k would allow
me to.
Axel DahmenI believe this has to do with the way the compiler works. By the time
you've hit the EXEC, it's too late to evaluate the expression. But it's
really not too bad:
DECLARE @.myVar3 VARCHAR(300)
SET @.MyVar3 = @.myVar + ' ' + @.myVar2
EXEC myProc @.MyVar3
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
news:uDecFY3PFHA.648@.TK2MSFTNGP14.phx.gbl...
> Hi,
> is there any reason why it is not allowed to use formulas as Stored
> Procedure parameters?
> e.g.: EXEC myProc(@.myVar + ' ' + @.myVar2)
> I could make use of this feature over and over if SQL Server 2k would
allow
> me to.
> Axel Dahmen
>|||Thanks, Adam.
I must admit that I'm not too satisfied with the current way of handling
this. I feel it's fairly awkward to write a bunch of lines like:
DECLARE @.myVar3 VARCHAR(300)
SET @.MyVar3 = @.myVar + ' ' + @.myVar2
EXEC myProc @.MyVar3
instead of just simply:
EXEC myProc @.myVar + ' ' + @.myVar2
particularly if you do things on-the-fly.
Do you perhaps know if SQL Server 2k5 will be able to process expressions in
procedure/UDF calls? If it doesn't, do you probably know about some channel
to suggest this functionality? It's nagging me for quite a while now. And
perhaps others might find a change in parsing procedure/UDF calls useful,
too.
Best wishes,
Axel
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> schrieb im
Newsbeitrag news:#5ZoPd3PFHA.3196@.TK2MSFTNGP12.phx.gbl...
> I believe this has to do with the way the compiler works. By the time
> you've hit the EXEC, it's too late to evaluate the expression. But it's
> really not too bad:
> DECLARE @.myVar3 VARCHAR(300)
> SET @.MyVar3 = @.myVar + ' ' + @.myVar2
> EXEC myProc @.MyVar3
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
> news:uDecFY3PFHA.648@.TK2MSFTNGP14.phx.gbl...
> allow
>|||> I feel it's fairly awkward
But necessary, so what are you going to do?
A workaround would be dynamic SQL, but it becomes quite complex as you have
varying data types being passed to the stored procedure.
> Do you perhaps know if SQL Server 2k5 will be able to process expressions
> in
> procedure/UDF calls?
No.
> If it doesn't, do you probably know about some channel
> to suggest this functionality?
sqlwish@.microsoft.com
> It's nagging me for quite a while now. And
> perhaps others might find a change in parsing procedure/UDF calls useful,
> too.
Frankly, the known workarounds are really not all that cumbersome, and I
think most people have just learned to live with the limitation and have
moved on. This sounds like the same kind of problem we have when people use
SELECT * or otherwise try avoid "all the hard work" of typing out a column
list.
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.|||"Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
news:uOU1kA4PFHA.2604@.TK2MSFTNGP10.phx.gbl...
> Do you perhaps know if SQL Server 2k5 will be able to process expressions
in
> procedure/UDF calls? If it doesn't, do you probably know about some
channel
> to suggest this functionality? It's nagging me for quite a while now. And
> perhaps others might find a change in parsing procedure/UDF calls useful,
> too.
No, the behavior won't change in SS2005 (at least, not based on anything
I've heard, and I've also just tested on the latest build -- same behavior).
I believe -- although someone else can hopefully back me up on this as I
don't know for certain -- that the behavior complies to the ANSI standard.
And if the standard doesn't support that, I wouldn't expect SQL Server to.
As I said, it has to do with the way the compiler works. SQL is compiled
using a very simple single-pass method. Re-doing that compilation for the
sake of this feature is not really a good use of time. There are a few
other features that could be done with multi-pass compilation, but I don't
think the SQL Server team would agree with me on how interesting I think
some of them are ;)
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
> Best wishes,
> Axel
>
> --
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> schrieb im
> Newsbeitrag news:#5ZoPd3PFHA.3196@.TK2MSFTNGP12.phx.gbl...
>|||I might be ignorant here, but even after giving it some deep thoughts I
don't find a reason why it should give the interpreter a hard time to accept
expressions instead of identifiers as procedure parameters.
The internal SQL Server part executing the SET statement could be used, for
instance, to interpret a given expression. The interpreter might create some
temporary dummy variable first to store the calculation result internally.
When calling a procedure/UDF a data type transformation call is triggered
internally for each parameter. So it's safe to assume that a parameter's
data format is already known to the interpreter. It should be easy then to
create such internal dummy variable to store the expression result and to
forward that result to the standard procedure/UDF call.
It would even be possible to have no additional execution costs compared to
the present (lacking)implementation. A cache could be implemented to hold
all temporary variables for the next call to the same procedure within the
same batch.
Program Flow:
- prepare procedure call
- WHILE parameter read
- if parameter is no legal identifier then
- create dummy variable to hold parameter
- SET {dummy variable} = parameter
- overwrite parameter to point to dummy variable
- add parameter to procedure call
- call procedure
RFC,
Axel Dahmen
www.sportbootcharter.com
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> schrieb im
Newsbeitrag news:#OH8lR4PFHA.2560@.TK2MSFTNGP14.phx.gbl...
> "Axel Dahmen" <NO_SPAM@.NoOneKnows.invalid> wrote in message
> news:uOU1kA4PFHA.2604@.TK2MSFTNGP10.phx.gbl...
expressions
> in
> channel
And
useful,
> No, the behavior won't change in SS2005 (at least, not based on
anything
> I've heard, and I've also just tested on the latest build -- same
behavior).
> I believe -- although someone else can hopefully back me up on this as I
> don't know for certain -- that the behavior complies to the ANSI standard.
> And if the standard doesn't support that, I wouldn't expect SQL Server to.
> As I said, it has to do with the way the compiler works. SQL is compiled
> using a very simple single-pass method. Re-doing that compilation for the
> sake of this feature is not really a good use of time. There are a few
> other features that could be done with multi-pass compilation, but I don't
> think the SQL Server team would agree with me on how interesting I think
> some of them are ;)
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
it's
would
>|||>> I might be ignorant here, but even after giving it some deep
thoughts I don't find a reason why it should give the interpreter a
hard time to accept expressions instead of identifiers as procedure
parameters. <<
In the early days of Sybase/SQL Server, we had a rule that you never
wrote over one page of T-SQL in a stored procedure or a trigger. It
was a kludge to get around the lack of DRI actions, DEFAULT, CHECK(),
etc, back in the Stone Age. It was never meant to be a full language.
The truth is that T-SQL was an early, one-pass compiler based on C; it
was not meant to do Thunks. One -pass compilers have a hell of a time
with Thunks; it takes two passes in most cases. Today T-SQL would be a
one-quarter senior project using a Compiler compiler, YACC or whatever.
Full strength application development languages came later. The
Informix 4GL isbased on the Algol family and a lot of mainframe
packages use it under the covers; it generated ANSI Standard C and is
very portable, has a report writer, etc. Progress started as a nice
application development 4GL which added SQL. PL/SQL in Oracle and the
Standard SQL/PSM are both based on ADA.
What we need is the Standard SQL/PSM instead of the CLR crap that is
about to destroy SQL Server databases (I have some anti-CLR rants
posted in various places).|||> The truth is that T-SQL was an early, one-pass compiler based on C; it
> was not meant to do Thunks. One -pass compilers have a hell of a time
> with Thunks; it takes two passes in most cases.
I appreciate that. But the SET command is already able do it. Thus I assume
the only change in procedure call processing should basically be to call the
SET command part after reading a parameter token. Perhaps there even is a
general expression parser part available in the interpreter that can be used
by T-SQL language coders at MS.
My main assumption is that:
if the T-SQL interpreter can process this (manual) sequence in one pass
DECLARE @.var ...
SET @.var = {expression}
EXEC proc @.var
then it can also do this automatically itself.
The most simple (and farmost worst) option would be to just expand any
parameter call to the above sequence internally. This deduction is my proof
of concept.
> What we need is the Standard SQL/PSM instead of the CLR crap that is
> about to destroy SQL Server databases (I have some anti-CLR rants
> posted in various places).
That's another story, but you're right, I agree with you. Giving too much
programming power to SQL Server will probably lead into decadence in design
in terms of a multi-tier model. And I'm also apprehensive of SQL Server 2005
becoming a slow performer and thus less scalable. Any Framework,
particularly .NET and Java by its nature of using IL, is slow and clumsy.
Well, it's a matter of consideration between RAD and performance. But enough
OT... ;)
Axel|||>> if the T-SQL interpreter can process this (manual) sequence in one
pass ... then it can also do this automatically itself. <<
Did you take a compiler writing course in college? I taught one :)
The simple ase is easy; the general case is a bear!
The compiler has to catch the general expression in the parameter,
adjust the scope of the declarations, fill in parameters in any
function calls, recursive function calls, self-references, etc. It
is not a simple matter of replacing a marker with "((<< expression
T-SQL sets error flags one statement at a time; SQL/PSM and modern
languages set multiple errors all at once based on BEGIN ATOMIC .. END
blocks. T-SQL was never meant for "industrial usage" in a modern
programming environment.|||> One -pass compilers have a hell of a time
> with Thunks; it takes two passes in most cases.
It took a few moments for me to see what you mean... The trick would be to
assume a destination data type to store the expression result in.
I guess there will be a feasible solution to that. For instance, every
expression calculated by SQL Server has an intrinsic data type. During
interpretation of the SET command the result is probably forwarded to the
data type converter part after calculation of the expression result. To
create a matching temporary memory space (or variable), this step ought to
be injected in between:
Assumed Standard SET Command Program Flow:
1) read destination variable
2) lookup destination variable in memory
3) read expression to be assigned
4) calculate expression
5) forward expression result and destination variable to
data type converter in order to store the converted
result into destination variable
To allow for dynamic destination variable creation, the flow could be
interjected with something like (one additional step added):
1) read expression to be assigned
2) calculate expression
* 3) create temporary destination variable from expression
data type
4) forward expression result and destination variable to
data type converter in order to store the converted
result into destination variable
5) provide destination variable to stored procedure
parameter
Regards,
Axel
No exception message from CLR stored procedure
Hello everybody,
I've encountered a strange thing using a CLR Stored procedure:
The procedure throws an exception with no message inside... value = {" "}
Basically the procedure has a string as argument which contains a SQL statement that changes according to the users selections...
The results of the query are saved into a dataset for further processing.
Those resultsets can sometimes be very big (ex: 15000 records...). (For the record the procedure works fine for smaller datasets ex 6000 records and running the same query on the application server returns the expected resultset )
By Debugging the procedure I could determine that the failing point was when the dataset is filled...
Anyone having any idea?
The only information I have from this exception is the stacktrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.CloseInternal(Boolean closeReader)
at System.Data.SqlClient.SqlDataReader.Close()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteScalar()
at DataAccess.runScalar(String strSQL, Boolean isStoredProcedure) in c:\Inetpub\wwwroot\Statistix\App_Code\DataAccess.cs:line 114
Thanks in advance
Alaindlk
Hello,
Still nobody having any idea of what is happening here?
Could it be possible that the SQL server is running out of memory or even having a connection timeout?
this is the procedure I've written that causes this behaviour:
[Microsoft.SqlServer.Server.SqlProcedure]
public static int Stats_Print_Data(string SqlQuery)
{
// Put your code here
int jobId = -1;
using (DataSet dsResults = new DataSet())
{
using (SqlConnection mConn = new SqlConnection("context connection = true"))
{
SqlCommand mCmd = new SqlCommand(SqlQuery, mConn);
mCmd.CommandTimeout = 100;
SqlDataAdapter mDa = new SqlDataAdapter(mCmd);
mDa.Fill(dsResults, "Print_Data");
if (dsResults.Tables[0].Rows.Count > 0)
{
ArrayList ColumnNames = new ArrayList();
for (int i = 8; i < dsResults.Tables[0].Columns.Count; i++)
{
DataColumn dc = dsResults.Tables[0].Columns;
ColumnNames.Add(dc.ColumnName);
}
StringBuilder InsertCommand = new StringBuilder();StringBuilder Values = new StringBuilder();
try
{
mConn.Open();
mCmd.CommandText = "Select max(report_id) from Statistix_Report";
jobId = System.Convert.ToInt16(mCmd.ExecuteScalar());
jobId++;
foreach (DataRow dr in dsResults.Tables[0].Rows)
{
if (InsertCommand.Length > 0) InsertCommand.Remove(0, InsertCommand.Length);
if (Values.Length > 0) Values.Remove(0, Values.Length);
mCmd.CommandText = "Select count(*) from print_data where AG_LIB = '" + dr[2].ToString().Replace("'", "''") +
"' and AN_LIB = '" + dr[3].ToString().Replace("'", "''") + "' and PRD_LIB = '" + dr[4].ToString().Replace("'", "''") +
"' and TM_LIB = '" + dr[5].ToString().Replace("'", "''") + "' and RM_LIB = '" + dr.ToString().Replace("'", "''") +
"' and SU_LIB = '" + dr[7].ToString().Replace("'", "''") + "'";
if (System.Convert.ToInt16(mCmd.ExecuteScalar()) > 0)
{
InsertCommand.Append("Update PRINT_DATA set ");
for (int i = 0; i < ColumnNames.Count; i++)
{
InsertCommand.Append(ColumnNames + "_" + int.Parse(dr["Month"].ToString()) + " = ");
if (dr[i + 8] != DBNull.Value)
{
InsertCommand.Append(dr[i + 8].ToString().Replace(",", "."));
}
else
{
InsertCommand.Append("0");
}
if (i != ColumnNames.Count - 1)
{
InsertCommand.Append(",");
}
}
InsertCommand.Append(" where AG_LIB = '" + dr[2].ToString().Replace("'", "''"));
InsertCommand.Append("' and AN_LIB = '" + dr[3].ToString().Replace("'", "''") + "' and PRD_LIB = '" + dr[4].ToString().Replace("'", "''"));
InsertCommand.Append("' and TM_LIB = '" + dr[5].ToString().Replace("'", "''") + "' and RM_LIB = '" + dr.ToString().Replace("'", "''"));
InsertCommand.Append("' and SU_LIB = '" + dr[7].ToString().Replace("'", "''") + "' and JOB_ID = " + jobId);
mCmd.CommandText = InsertCommand.ToString();
mCmd.ExecuteNonQuery();
}
else
{
Values = new StringBuilder();
InsertCommand = new StringBuilder();
InsertCommand.Append("insert into print_data(AG_LIB,AN_LIB,PRD_LIB,TM_LIB,RM_LIB,SU_LIB,JOB_ID,");
Values.Append("'" + dr[2].ToString().Replace("'", "''") + "','" + dr[3].ToString().Replace("'", "''") + "','");
Values.Append(dr[4].ToString().Replace("'", "''") + "','" + dr[5].ToString().Replace("'", "''") + "','");
Values.Append(dr.ToString().Replace("'", "''") + "','" + dr[7].ToString().Replace("'", "''") + "'," + jobId + ",");
for (int i = 0; i < ColumnNames.Count; i++)
{
InsertCommand.Append(ColumnNames + "_" + int.Parse(dr["Month"].ToString()));
if (dr[i + 8] != DBNull.Value)
{
Values.Append(dr[i + 8].ToString().Replace(",", "."));
}
else Values.Append("0");
if (i != ColumnNames.Count - 1)
{
InsertCommand.Append(",");
Values.Append(",");
}
}
InsertCommand.Append(") values (");
InsertCommand.Append(Values.ToString() + ")");
mCmd.CommandText = InsertCommand.ToString();
mCmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
throw new Exception(InsertCommand.ToString(), ex);}
finally
{
mCmd.Dispose();
mConn.Close();
}
}}
}
return jobId;
}
Any help would be greatly appreciated...
How can i debug something like this?
Thanks in advance
|||Are you sure that it is the error message thrown by SqlClient is empty and not the exception you throw here:
catch (Exception ex)
{
throw new Exception(InsertCommand.ToString(), ex);
}
? What happens if you remove this catch block and let the unhandled exception get propogated back to sql server - is it still empty?
|||Hello Steven,
Thanks for your reply...
The exception I've given above is effectively thrown by the stored procedure...
Further investigation learned me that it was indeed a timeout of the stored procedure, so I deed improve the indexing on the tables which now solves partly my problem...
However The problem still remains as the stored procedure, after fetching the required data, saves this data into a table for reporting. The problem is that each 12 rows in the dataset has to be transformed as one record with 12 columns (Table sucks but I have to work with this solution imposed to me ) This means I first need to know if the record already exists, if not then create an insert statement else create an update statement.
Now it seems that executing this causes a timeout for the procedure.
Is there any way to increase this timeout period?
Hello everybody,
I think I've finally found the reason why this timeout occurs: Thats because of the fact that the stored procedure returns a value...
In the worst case, my procedure takes about 10 minutes to complete.... letting the Application server waiting that long is "unacceptable". I think that SQL server automatically throws a timeout exception whenever a procedure/ function takes to long to complete.
I've solved this by changing the procedure signature from Static int SP_Name to static void SP_name(); This way the procedure doesn't have to return a value and isn't any more interrupted by a timeout thrown by SQL server...
Can anyone confirm me this behaviour of SQL server? (By the way this solution works fine for me now...)
Thanks in advance
Monday, March 26, 2012
No Display Output using Stored Procedure
the browse area when I run the procedure in the data window. I have
manually listed all fields in the Dataset->Fields window and drag them into
the Layout screen.
When I try to preview the report it seems to load the rows (ie 7 pages are
shown as loaded) but doesn't display any data, only the headings show with
and blank body section. If a put a string literal in one field it appears
on each row of the report but all other fields are blank.
I've looked through Output Options without any joy...Could you please post the rdl and ddl for a stored procedure that goes
against any of the sample databases so I can investigate?
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"spamh8ers" <spamh8ers@.discussions.microsoft.com> wrote in message
news:2C2EC175-8681-42F9-A398-CAF83DEE765C@.microsoft.com...
> Does anyone have a solution for this yet? I have similar issues with
> creating new reports. If I start the the report with text query like
Select
> SalesOrder from SalesOrders, the report runs with no problem but when I
> change to a stored procedure, I get pages of empty report body.
> Ideas or workarounds?
> "news.microsoft.com" wrote:
> > I call a stored procedure from the RS Data area and all data is
retrieved on
> > the browse area when I run the procedure in the data window. I have
> > manually listed all fields in the Dataset->Fields window and drag them
into
> > the Layout screen.
> >
> > When I try to preview the report it seems to load the rows (ie 7 pages
are
> > shown as loaded) but doesn't display any data, only the headings show
with
> > and blank body section. If a put a string literal in one field it
appears
> > on each row of the report but all other fields are blank.
> >
> > I've looked through Output Options without any joy...
> >
> >
> >
Friday, March 23, 2012
No columns defined in rowset
I have a stored procedure. I used ADO to called this stored procedure. In
runtime, it says "No columns defined in rowset".
Here is my stored procedure:
========================================
========
CREATE PROCEDURE [sp_MigrateAccount]
@.i_vchSessionID VARCHAR(50),
@.o_intRetVal int OUTPUT
AS
-- Variables for error handling.
DECLARE @.intError int
DECLARE @.insAcct_error int
DECLARE @.insAcctSum_error int
DECLARE @.insAddr_error int
DECLARE @.drop_error int
DECLARE @.intRecordErrorCounter int
-- Temporary storage
DECLARE @.chSourceAccountID char(12)
DECLARE @.vchSourceAccount char(128)
DECLARE @.vchSourceMainPhone char(32)
DECLARE @.vchSourceFax char(32)
DECLARE @.chSourceUserfield5 char(80)
DECLARE @.m_cintMigrateSucceed int
DECLARE @.m_cintRecordDataError int
DECLARE @.m_cintInsertToRealTableError int
DECLARE @.m_cintDuplicateKeyError int
SET NOCOUNT ON
-- Assign value to constants
SET @.m_cintMigrateSucceed = 0
SET @.m_cintRecordDataError = 2
SET @.m_cintInsertToRealTableError = 3
SET @.m_cintDuplicateKeyError = 7
-- Perform data validation --
-- Check for duplicate ACCOUNTID
SET @.intRecordErrorCounter = 0
SELECT @.intRecordErrorCounter = COUNT (a1.ACCOUNTID)
FROM sysdba.ACCOUNT AS a1
WHERE a1.ACCOUNTID IN
(SELECT ACCOUNTID
FROM ACCOUNT_TEMP
WHERE SessionID = @.i_vchSessionID)
IF (@.intRecordErrorCounter > 0) -- There exists at least one validation
error.
BEGIN
-- Update ErrorColumn in the source table. --
-- 1 is an arbitrary value for the ErrorColumn.
-- If ErrorColumn is NULL or 0, this record has no error.
UPDATE sysdba.ACCOUNT_TEMP
SET ErrorColumn = @.m_cintDuplicateKeyError
WHERE (SessionID = @.i_vchSessionID)
AND ACCOUNTID IN
(SELECT ACCOUNTID
FROM ACCOUNT)
-- No need to update the destination table, thus we quit the SP
-- Note that the error number used by SQL Server is greater than 0.
SET @.intError = @.m_cintDuplicateKeyError
GOTO Quit_SP
END
-- Up to this point, the data validation is passed.
-- We can insert record into the destination table. now.
BEGIN TRAN dataMigration
-- Insert records to the ACCOUNT table
-- People from newsgroup said that you are required to
-- enter uppercase Account Name into ACCOUNT_UC field.
INSERT INTO ACCOUNT
(ACCOUNTID, ACCOUNT, MAINPHONE, FAX, [DESCRIPTION], SECCODEID,
ADDRESSID, SHIPPINGID, ACCOUNTMANAGERID, CREATEUSER, MODIFYUSER,
CREATEDATE,
MODIFYDATE, ACCOUNT_UC)
SELECT ACCOUNTID, ACCOUNT, MAINPHONE, FAX, [DESCRIPTION], SECCODEID,
ADDRESSID, SHIPPINGID, ACCOUNTMANAGERID, CREATEUSER, MODIFYUSER,
CREATEDATE,
MODIFYDATE, ACCOUNT_UC
FROM sysdba.ACCOUNT_TEMP
WHERE SessionID = @.i_vchSessionID
SET @.insAcct_error = @.@.ERROR
IF (0 = @.insAcct_error) BEGIN
COMMIT TRAN dataMigration
END
ELSE
BEGIN
IF (0 <> @.insAcct_error)
-- Const m_cintInsertToRealTableError = 3
SET @.intError = @.m_cintInsertToRealTableError
ROLLBACK TRAN dataMigration
END
Error_Handler:
Quit_SP:
IF (@.intError IS NULL)
-- No value assigned to @.intError in the
-- body of this stored procedure.
-- Thus, migrate data is successful.
-- Const m_cintMigrateSucceed = 0
SET @.o_intRetVal = @.m_cintMigrateSucceed
ELSE
SET @.o_intRetVal = @.intError -- Failure encountered.
RETURN
GO
========================================
=
Here is my VBScript that used ADO to call the store procedure:
========================================
===
' :
' ADO database connection....
' :
With ADOCmd
.CommandText = "sp_MigrateAccount"
.CommandType = adCmdStoredProc
strInputText = i_strSessionID
lngParamLen = Len(strInputText)
If lngParamLen <= 0 Then
lngParamLen = 1
End If
Set ADOParam = .CreateParameter("@.i_vchType", adVarChar,
adParamInput, lngParamLen, strInputText)
.Parameters.Append ADOParam
Set ADOParam = .CreateParameter("@.o_intRetVal", adInteger,
adParamOutput)
.Parameters.Append ADOParam
Set .ActiveConnection = objCon
.Execute
lngRetVal = .Parameters("@.o_intRetVal").Value
End With
' :
' :
' :
'=======================================
==
The ".Execute" statement caused the "No columns defined in rowset".
If I try the following statement:
.Execute , , (adCmdStoredProc Or adExecuteNoRecords)
Or,
.Execute , , adExecuteNoRecords
I cannot get the output value (@.o_intRetVal) from the stored procedure.
May I know how to solve this problem? Thanks a lot.
SammySa wrote:
> Hello Experts,
> I have a stored procedure. I used ADO to called this stored
> procedure. In runtime, it says "No columns defined in rowset".
That does not sound like an ADO error. It sounds more like a T-SQL error.
ADO errors usually refer to recordsets, fields and records. "rowset" makes
it sound
like a T-SQL error.
Have you verified that this procedure runs correctly in Query Analyzer? Like
this:
declare @.ret int
exec sp_MigrateAccount 'some session id',@.ret output
select @.ret [Output Value]
> Here is my stored procedure:
> ========================================
========
> CREATE PROCEDURE [sp_MigrateAccount]
Nothing to do with your error, but using "sp_" for a non-system stored
procedure can cause a slight performance dip, since the query engine treats
all procedures beginning with this prefix as system procedures, looking for
them first in Master, and only looking for them in the current database when
it fails to find them in Master. If you mistakenly name your procedure the
same as a real system procedure, you've got a knotty debugging problem ahead
of you ...
> @.i_vchSessionID VARCHAR(50),
> @.o_intRetVal int OUTPUT
> AS
> -- Variables for error handling.
> DECLARE @.intError int
<snip>
> SET NOCOUNT ON
I doubt this is the problem, but I generally make this the first statement
in my procedures - before any other statement, even DECLARE's.
>
<snip>
> ========================================
=
>
> Here is my VBScript that used ADO to call the store procedure:
> ========================================
===
> ' :
> ' ADO database connection....
> ' :
> With ADOCmd
> .CommandText = "sp_MigrateAccount"
> .CommandType = adCmdStoredProc
> strInputText = i_strSessionID
> lngParamLen = Len(strInputText)
> If lngParamLen <= 0 Then
> lngParamLen = 1
> End If
> Set ADOParam = .CreateParameter("@.i_vchType", adVarChar,
> adParamInput, lngParamLen, strInputText)
> .Parameters.Append ADOParam
> Set ADOParam = .CreateParameter("@.o_intRetVal",
> adInteger, adParamOutput)
> .Parameters.Append ADOParam
> Set .ActiveConnection = objCon
> .Execute
> lngRetVal = .Parameters("@.o_intRetVal").Value
> End With
> ' :
> ' :
> ' :
> '=======================================
==
> The ".Execute" statement caused the "No columns defined in rowset".
> If I try the following statement:
> .Execute , , (adCmdStoredProc Or adExecuteNoRecords)
Should be:
.Execute , , (adCmdStoredProc + adExecuteNoRecords)
HTH,
Bob Barrows
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.sql
No column to map
Hello,
I am using oledb source and running sp_helpdb procedure but when I open the columns windows there are no column available.
your help is appreciated.
Thanks.
got the answer workaround is to use
SET FMTONLY OFF
Wednesday, March 7, 2012
Newly created stored procedure => master db
create stored procedures under the database that I created. It seems as if
any new procs are created in the master database.
If I create a new proc, it is not displayed under the stored procedure
folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
Studio Express\Projects along with the other procs that I'd created prior to
the upgrade.
If I open the newly created proc then I'm asked to login to the SQL Express
again (I already have Management Studio Express open and logged in to my own
database). Once the proc is open , the combo box "available databases" on the
toolbar displayes, 'master'. So it seems I've logged in to the master
database where the new proc has been created. But it is not displayed in the
Stored Procs of the master either.
What has gone wrong? I should be able to create new stored procs in my
database and not in the master database.
Can someone help - thanksLisa
What is happenening if you issue?
USE mydb
GO
CREATE PROC mmmm
AS
....
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>I have upgraded my SQLExpress to SP1 but since doing this I am not able to
> create stored procedures under the database that I created. It seems as if
> any new procs are created in the master database.
> If I create a new proc, it is not displayed under the stored procedure
> folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
> Studio Express\Projects along with the other procs that I'd created prior
> to
> the upgrade.
> If I open the newly created proc then I'm asked to login to the SQL
> Express
> again (I already have Management Studio Express open and logged in to my
> own
> database). Once the proc is open , the combo box "available databases" on
> the
> toolbar displayes, 'master'. So it seems I've logged in to the master
> database where the new proc has been created. But it is not displayed in
> the
> Stored Procs of the master either.
> What has gone wrong? I should be able to create new stored procs in my
> database and not in the master database.
> Can someone help - thanks|||Thanks for your response. Unfortunately it makes no difference. I created the
new proc and then opened it, but the Connect to Database Engine dialog box is
displayed and I connect to the master db.
"Uri Dimant" wrote:
> Lisa
> What is happenening if you issue?
> USE mydb
> GO
> CREATE PROC mmmm
> AS
> .....
>
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
> >I have upgraded my SQLExpress to SP1 but since doing this I am not able to
> > create stored procedures under the database that I created. It seems as if
> > any new procs are created in the master database.
> >
> > If I create a new proc, it is not displayed under the stored procedure
> > folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
> > Studio Express\Projects along with the other procs that I'd created prior
> > to
> > the upgrade.
> >
> > If I open the newly created proc then I'm asked to login to the SQL
> > Express
> > again (I already have Management Studio Express open and logged in to my
> > own
> > database). Once the proc is open , the combo box "available databases" on
> > the
> > toolbar displayes, 'master'. So it seems I've logged in to the master
> > database where the new proc has been created. But it is not displayed in
> > the
> > Stored Procs of the master either.
> >
> > What has gone wrong? I should be able to create new stored procs in my
> > database and not in the master database.
> > Can someone help - thanks
>
>|||Lisa
Ok, it is by default. You can change it by using
EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...
> Thanks for your response. Unfortunately it makes no difference. I created
> the
> new proc and then opened it, but the Connect to Database Engine dialog box
> is
> displayed and I connect to the master db.
>
> "Uri Dimant" wrote:
>> Lisa
>> What is happenening if you issue?
>> USE mydb
>> GO
>> CREATE PROC mmmm
>> AS
>> .....
>>
>> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in
>> message
>> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>> >I have upgraded my SQLExpress to SP1 but since doing this I am not able
>> >to
>> > create stored procedures under the database that I created. It seems as
>> > if
>> > any new procs are created in the master database.
>> >
>> > If I create a new proc, it is not displayed under the stored procedure
>> > folder. Iit is displayed in the folder c:\mydocuments\SQL
>> > ServerManagement
>> > Studio Express\Projects along with the other procs that I'd created
>> > prior
>> > to
>> > the upgrade.
>> >
>> > If I open the newly created proc then I'm asked to login to the SQL
>> > Express
>> > again (I already have Management Studio Express open and logged in to
>> > my
>> > own
>> > database). Once the proc is open , the combo box "available databases"
>> > on
>> > the
>> > toolbar displayes, 'master'. So it seems I've logged in to the master
>> > database where the new proc has been created. But it is not displayed
>> > in
>> > the
>> > Stored Procs of the master either.
>> >
>> > What has gone wrong? I should be able to create new stored procs in my
>> > database and not in the master database.
>> > Can someone help - thanks
>>|||Uri
I don't want to seem ignorant but where do I use this. I'm using Access as
my front end and SQLExpress as the backend. :(
Also - I'm not able to modify any of the previous stored procs. If I make a
modification and save by overwriting the proc, the changes are not there when
I open the proc again.
"Uri Dimant" wrote:
> Lisa
> Ok, it is by default. You can change it by using
> EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
> news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...
> > Thanks for your response. Unfortunately it makes no difference. I created
> > the
> > new proc and then opened it, but the Connect to Database Engine dialog box
> > is
> > displayed and I connect to the master db.
> >
> >
> > "Uri Dimant" wrote:
> >
> >> Lisa
> >> What is happenening if you issue?
> >> USE mydb
> >> GO
> >> CREATE PROC mmmm
> >> AS
> >> .....
> >>
> >>
> >> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in
> >> message
> >> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
> >> >I have upgraded my SQLExpress to SP1 but since doing this I am not able
> >> >to
> >> > create stored procedures under the database that I created. It seems as
> >> > if
> >> > any new procs are created in the master database.
> >> >
> >> > If I create a new proc, it is not displayed under the stored procedure
> >> > folder. Iit is displayed in the folder c:\mydocuments\SQL
> >> > ServerManagement
> >> > Studio Express\Projects along with the other procs that I'd created
> >> > prior
> >> > to
> >> > the upgrade.
> >> >
> >> > If I open the newly created proc then I'm asked to login to the SQL
> >> > Express
> >> > again (I already have Management Studio Express open and logged in to
> >> > my
> >> > own
> >> > database). Once the proc is open , the combo box "available databases"
> >> > on
> >> > the
> >> > toolbar displayes, 'master'. So it seems I've logged in to the master
> >> > database where the new proc has been created. But it is not displayed
> >> > in
> >> > the
> >> > Stored Procs of the master either.
> >> >
> >> > What has gone wrong? I should be able to create new stored procs in my
> >> > database and not in the master database.
> >> > Can someone help - thanks
> >>
> >>
> >>
>
>
Newly created stored procedure => master db
create stored procedures under the database that I created. It seems as if
any new procs are created in the master database.
If I create a new proc, it is not displayed under the stored procedure
folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
Studio Express\Projects along with the other procs that I'd created prior to
the upgrade.
If I open the newly created proc then I'm asked to login to the SQL Express
again (I already have Management Studio Express open and logged in to my own
database). Once the proc is open , the combo box "available databases" on th
e
toolbar displayes, 'master'. So it seems I've logged in to the master
database where the new proc has been created. But it is not displayed in the
Stored Procs of the master either.
What has gone wrong? I should be able to create new stored procs in my
database and not in the master database.
Can someone help - thanksLisa
What is happenening if you issue?
USE mydb
GO
CREATE PROC mmmm
AS
....
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>I have upgraded my SQLExpress to SP1 but since doing this I am not able to
> create stored procedures under the database that I created. It seems as if
> any new procs are created in the master database.
> If I create a new proc, it is not displayed under the stored procedure
> folder. Iit is displayed in the folder c:\mydocuments\SQL ServerManagement
> Studio Express\Projects along with the other procs that I'd created prior
> to
> the upgrade.
> If I open the newly created proc then I'm asked to login to the SQL
> Express
> again (I already have Management Studio Express open and logged in to my
> own
> database). Once the proc is open , the combo box "available databases" on
> the
> toolbar displayes, 'master'. So it seems I've logged in to the master
> database where the new proc has been created. But it is not displayed in
> the
> Stored Procs of the master either.
> What has gone wrong? I should be able to create new stored procs in my
> database and not in the master database.
> Can someone help - thanks|||Thanks for your response. Unfortunately it makes no difference. I created th
e
new proc and then opened it, but the Connect to Database Engine dialog box i
s
displayed and I connect to the master db.
"Uri Dimant" wrote:
> Lisa
> What is happenening if you issue?
> USE mydb
> GO
> CREATE PROC mmmm
> AS
> .....
>
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in messag
e
> news:430A9254-6539-4C84-8C57-DBC4E3C0AADA@.microsoft.com...
>
>|||Lisa
Ok, it is by default. You can change it by using
EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
"Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in message
news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...[vbcol=seagreen]
> Thanks for your response. Unfortunately it makes no difference. I created
> the
> new proc and then opened it, but the Connect to Database Engine dialog box
> is
> displayed and I connect to the master db.
>
> "Uri Dimant" wrote:
>|||Uri
I don't want to seem ignorant but where do I use this. I'm using Access as
my front end and SQLExpress as the backend.
Also - I'm not able to modify any of the previous stored procs. If I make a
modification and save by overwriting the proc, the changes are not there whe
n
I open the proc again.
"Uri Dimant" wrote:
> Lisa
> Ok, it is by default. You can change it by using
> EXEC sp_defaultdb 'Lisa', 'AdventureWorks'
> "Lisa Tanenbaum" <LisaTanenbaum@.discussions.microsoft.com> wrote in messag
e
> news:16DB04B0-8E9B-4C8C-88FD-F881A31AA781@.microsoft.com...
>
>
Saturday, February 25, 2012
Newbie: stored procedure stops and exits prematurely
it to stored procedure writing...But my inexperience is showing, I'm
afraid...Can anyone point out what I should be doing here? Thank you...
I'm pulling several steps together into one stored procedure, but the
procedure stops and exits at the first step in order to return a message box
that says "The stored procedure executed successfully but did not return
records."
How can I tell the SP to continue to execute? Or, how can I avoid getting
the message?
Synopsis of the SP:
The purpose is to allow the user to select individuals to receive an
emailing. (The SP is called from the form.) Before presenting the list of
contacts on the form, I want to make sure that any new contacts in the
Contacts table get added to the SelectForEmail table . (The Contacts table
is part of a replicated database, to which I cannot add a trigger.)
Step 1: Behind the scenes, add any new contacts to the table SelectForEmail.
Step 2: Present the form that allows the user to check off the individuals
that should receive the emailing.
Here's the code for the first step:
/* Get all contacts from the contacts table */
INSERT INTO dbo.SelectForEmail (Contact_ID)
SELECT dbo.Contacts.Contact_ID FROM dbo.Contacts
LEFT OUTER JOIN dbo.SelectForEmail
ON dbo.Contacts.Contact_ID = dbo.SelectForEmail.Contact_ID
WHERE (dbo.SelectForEmail.Contact_ID IS NULL)> How can I tell the SP to continue to execute? Or, how can I avoid getting
> the message?
Perhaps the Procedure already executed but you didnt issued a command to
display any data ?
Create procedure DisplaySomeData
AS
INSERT INTO sometable values (1)
GO
--> Wont display any data
Create procedure DisplaySomeData
AS
INSERT INTO sometable values (1)
Select * from Sometable where ID = 1
GO
--> Will display data
It hard to tell what you have to do without having some of the DDL of your
procedure, please post some DDL and thatll try to help us to help you.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Kaycee Heyer" <heyerk@.uncw.edu> schrieb im Newsbeitrag
news:uISPrHKVFHA.3252@.TK2MSFTNGP10.phx.gbl...
> Well thanks to a lot of reading and experimentation, as a newbie, I've
> made
> it to stored procedure writing...But my inexperience is showing, I'm
> afraid...Can anyone point out what I should be doing here? Thank you...
> I'm pulling several steps together into one stored procedure, but the
> procedure stops and exits at the first step in order to return a message
> box
> that says "The stored procedure executed successfully but did not return
> records."
> How can I tell the SP to continue to execute? Or, how can I avoid getting
> the message?
> Synopsis of the SP:
> The purpose is to allow the user to select individuals to receive an
> emailing. (The SP is called from the form.) Before presenting the list of
> contacts on the form, I want to make sure that any new contacts in the
> Contacts table get added to the SelectForEmail table . (The Contacts table
> is part of a replicated database, to which I cannot add a trigger.)
> Step 1: Behind the scenes, add any new contacts to the table
> SelectForEmail.
> Step 2: Present the form that allows the user to check off the individuals
> that should receive the emailing.
> Here's the code for the first step:
>
> /* Get all contacts from the contacts table */
> INSERT INTO dbo.SelectForEmail (Contact_ID)
> SELECT dbo.Contacts.Contact_ID FROM dbo.Contacts
> LEFT OUTER JOIN dbo.SelectForEmail
> ON dbo.Contacts.Contact_ID = dbo.SelectForEmail.Contact_ID
> WHERE (dbo.SelectForEmail.Contact_ID IS NULL)
>|||Thanks.
I found that if I do the SELECT first, and then check @.@.ROWCOUNT <> 0
before doing the INSERT, that I can avoid getting the message.
Here's the entire new procedure:
ALTER PROCEDURE SEGM_EmailSelect4List
AS
/* Add new contacts from the contacts table */
/* Check first to make sure that new contacts exist */
SELECT dbo.Contacts.Contact_ID
FROM dbo.Contacts LEFT OUTER JOIN
dbo.SEGM_SelectForEmail ON
dbo.Contacts.Contact_ID = dbo.SEGM_SelectForEmail.Contact_ID
WHERE (dbo.SEGM_SelectForEmail.Contact_ID IS NULL)
IF @.@.ROWCOUNT <> 0
BEGIN
/* Add new contacts from the contacts table */
INSERT INTO dbo.SEGM_SelectForEmail
(Contact_ID)
SELECT dbo.Contacts.Contact_ID
FROM dbo.Contacts LEFT OUTER JOIN
dbo.SEGM_SelectForEmail ON
dbo.Contacts.Contact_ID = dbo.SEGM_SelectForEmail.Contact_ID
WHERE (dbo.SEGM_SelectForEmail.Contact_ID IS NULL)
END
/* Flag any contacts who have been investigators (that is, they exist in
the Investigators table) */
UPDATE dbo.SEGM_SelectForEmail
SET SEGM_Investigator = 1, SelectForEmail = 1
WHERE (Contact_ID IN
(SELECT dbo.Investigators.Contact_ID
FROM dbo.Investigators))
/* Return all contacts to the form that called us */
SELECT TOP 100 PERCENT dbo.Contacts.Last_Name,
dbo.Contacts.First_Name, dbo.Contacts.E_mail,
dbo.SEGM_SelectForEmail.SEGM_Investigator,
dbo.SEGM_SelectForEmail.SelectForEmail,
dbo.Affiliations.Affiliation
FROM dbo.Contacts
INNER JOIN dbo.SEGM_SelectForEmail ON
dbo.Contacts.Contact_ID = dbo.SEGM_SelectForEmail.Contact_ID
INNER JOIN dbo.Organizations ON dbo.Contacts.Organization_ID =
dbo.Organizations.Organization_ID
INNER JOIN dbo.Affiliations ON dbo.Organizations.Affiliation_ID =
dbo.Affiliations.Affiliation_ID
WHERE 1=1
ORDER BY dbo.Contacts.Last_Name, dbo.Contacts.First_Name
But now I have a new problem. The last select returns 0 rows to the form
opened in datasheet view. When I remove all the code except the last
select, it returns many rows.
What's going on?
*** Sent via Developersdex http://www.examnotes.net ***