Friday, March 30, 2012

question about sp_generate_inserts (Vyas's SP)

Hello,
I compiled Vyas's SP sp_generate_inserts
(http://vyaskn.tripod.com/code/generate_inserts.txt) and it works perfectly
on my test servers - all except one server. On this server, I get the
following errors
Server: Msg 536, Level 16, State 3, Procedure sp_generate_inserts1, Line 332
Invalid length parameter passed to the substring function.
Server: Msg 536, Level 16, State 1, Procedure sp_generate_inserts1, Line 333
Invalid length parameter passed to the substring function.
Server: Msg 50000, Level 16, State 1, Procedure sp_generate_inserts1, Line 3
37
No columns to select. There should at least be one column to generate the
output
(I compiled the SP onto the master database and am executing the SP as
EXEC sp_generate_inserts1 @.table_name='MyTableName') in the context of the
database where "MytableName" exists
The following statement seems to be returning a NULL (I modified the SP to
display @.Column_ID)
SELECT @.Column_ID = MIN(ORDINAL_POSITION)
FROM INFORMATION_SCHEMA.COLUMNS (NOLOCK)
WHERE TABLE_NAME = @.table_name AND
(@.owner IS NULL OR TABLE_SCHEMA = @.owner)
In fact, when I put the following SELECT
SELECT top 10 * from INFORMATION_SCHEMA.COLUMNS (NOLOCK)
in place of the original SELECT (above), I get rows with
TABLE_CATALOG='Master'
It almost looks like the SP is selecting from the Master database instead of
the user database that I have selected.
If I change the SELECT to hardcode the database name (as shown below), the
insert statements are generated correctly!
SELECT @.Column_ID = MIN(ORDINAL_POSITION)
FROM <myDBNAME>.INFORMATION_SCHEMA.COLUMNS (NOLOCK)
WHERE TABLE_NAME = @.table_name AND
(@.owner IS NULL OR TABLE_SCHEMA = @.owner)
I have double checked to verify that I am running the EXEC in the correct
database (not the master database) and have also confirmed that the
sp_generate_inserts doesn't exist in any other database.
This SP works perfectly on two other servers that I have tried this on, so I
am baffled!
Any suggestions on how to debug this?
Thanks!Hi
This sounds like you need to call
EXEC sp_MS_marksystemobject sp_generate_inserts1
Have you checked
SELECT OBJECTPROPERTY ( OBJECT_ID(sp_generate_inserts1), 'IsMSShipped' )
John
"Bob" wrote:

> Hello,
> I compiled Vyas's SP sp_generate_inserts
> (http://vyaskn.tripod.com/code/generate_inserts.txt) and it works perfectl
y
> on my test servers - all except one server. On this server, I get the
> following errors
> Server: Msg 536, Level 16, State 3, Procedure sp_generate_inserts1, Line 3
32
> Invalid length parameter passed to the substring function.
> Server: Msg 536, Level 16, State 1, Procedure sp_generate_inserts1, Line 3
33
> Invalid length parameter passed to the substring function.
> Server: Msg 50000, Level 16, State 1, Procedure sp_generate_inserts1, Line
337
> No columns to select. There should at least be one column to generate the
> output
> (I compiled the SP onto the master database and am executing the SP as
> EXEC sp_generate_inserts1 @.table_name='MyTableName') in the context of the
> database where "MytableName" exists
> The following statement seems to be returning a NULL (I modified the SP to
> display @.Column_ID)
> SELECT @.Column_ID = MIN(ORDINAL_POSITION)
> FROM INFORMATION_SCHEMA.COLUMNS (NOLOCK)
> WHERE TABLE_NAME = @.table_name AND
> (@.owner IS NULL OR TABLE_SCHEMA = @.owner)
> In fact, when I put the following SELECT
> SELECT top 10 * from INFORMATION_SCHEMA.COLUMNS (NOLOCK)
> in place of the original SELECT (above), I get rows with
> TABLE_CATALOG='Master'
> It almost looks like the SP is selecting from the Master database instead
of
> the user database that I have selected.
> If I change the SELECT to hardcode the database name (as shown below), the
> insert statements are generated correctly!
> SELECT @.Column_ID = MIN(ORDINAL_POSITION)
> FROM <myDBNAME>.INFORMATION_SCHEMA.COLUMNS (NOLOCK)
> WHERE TABLE_NAME = @.table_name AND
> (@.owner IS NULL OR TABLE_SCHEMA = @.owner)
> I have double checked to verify that I am running the EXEC in the correct
> database (not the master database) and have also confirmed that the
> sp_generate_inserts doesn't exist in any other database.
> This SP works perfectly on two other servers that I have tried this on, so
I
> am baffled!
> Any suggestions on how to debug this?
> Thanks!|||Thank you John! That resolved it! I now renamed the SP back to
sp_generate_insert (I had added the 1 at the end to make sure that the SP
didn't exist anywhere else).
and it is working!
Just curious - Normally, shouldn't this be set to a system object when I
compile it into the master database? (it worked on my other servers without
having to call sp_MS_marksystemobject)
Thanks again!
"John Bell" wrote:
> Hi
> This sounds like you need to call
> EXEC sp_MS_marksystemobject sp_generate_inserts1
> Have you checked
> SELECT OBJECTPROPERTY ( OBJECT_ID(sp_generate_inserts1), 'IsMSShipped' )
> John
> "Bob" wrote:
>|||Hi
The install script uses another undocumented procedure
sp_MS_upd_sysobj_category
see http://tinyurl.com/bxpyp for an explanation.
sp_MS_upd_sysobj_category uses trace flag 1717 so that when you create the
procedure the MSShipped bit is automagically set, sp_MS_marksystemobject
updates sysobjects directly.
John
"Bob" <Bob@.discussions.microsoft.com> wrote in message
news:2AA1210D-1636-435C-AAE0-D4D0C8C243DE@.microsoft.com...
> Thank you John! That resolved it! I now renamed the SP back to
> sp_generate_insert (I had added the 1 at the end to make sure that the SP
> didn't exist anywhere else).
> and it is working!
> Just curious - Normally, shouldn't this be set to a system object when I
> compile it into the master database? (it worked on my other servers
> without
> having to call sp_MS_marksystemobject)
> Thanks again!
> "John Bell" wrote:
>sql

No comments:

Post a Comment