NAnt sql task fails, but code works in SQL Query Analyzer

View: New views
6 Messages — Rating Filter:   Alert me  

NAnt sql task fails, but code works in SQL Query Analyzer

by Artie Leech :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm trying to create a nant task that will build my database, which uses SQL Server 2000.

I have the following line in a loop to load up a number of stored procs.

<sql connstring="${database.project.connstring}" delimiter="GO" transaction="true" batch="false" delimstyle="Normal" source="${database.ddl.filename}"/>


It's trying to load the stored proc code shown at the bottom of this post.

When I run my nant task, I get the following error:


"BUILD FAILED - 2 non-fatal error(s), 0 warning(s)
default.build(52,22):
Error while executing SQL statement.
    Object reference not set to an instance of an object."

However, if I remove the line "IF @@ERROR <> 0 GOTO finish", from the code below, then the build succeeds.

Loading the proc through SQL Server Query Analyzer works fine - it's just from the NAnt sql task it fails.

Any ideas as to what I'm missing here?

Any help much appreciated!

Artie


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spr_myStoredProc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spr_myStoredProc]
GO

CREATE PROCEDURE [dbo].[spr_myStoredProc] AS

DECLARE @stat     int

BEGIN

DELETE
FROM dbo.tbl_myTable

SET @stat=@@ERROR
IF @@ERROR <> 0 GOTO finish

-- other stuff edited out to narrow down the nant sql error

finish:

RETURN @stat
END

Re: NAnt sql task fails, but code works in SQL Query Analyzer

by Artie Leech :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've narrowed it down further:

The problematic line is "IF @@ERROR <> 0 GOTO finish".

If I change this even to just "GOTO finish" I still get the error.
If I remove the line completely, my nant sql task works just fine.

Am I missing something really obvious?

Artie Leech wrote:
Hi,

I'm trying to create a nant task that will build my database, which uses SQL Server 2000.

I have the following line in a loop to load up a number of stored procs.

<sql connstring="${database.project.connstring}" delimiter="GO" transaction="true" batch="false" delimstyle="Normal" source="${database.ddl.filename}"/>


It's trying to load the stored proc code shown at the bottom of this post.

When I run my nant task, I get the following error:


"BUILD FAILED - 2 non-fatal error(s), 0 warning(s)
default.build(52,22):
Error while executing SQL statement.
    Object reference not set to an instance of an object."

However, if I remove the line "IF @@ERROR <> 0 GOTO finish", from the code below, then the build succeeds.

Loading the proc through SQL Server Query Analyzer works fine - it's just from the NAnt sql task it fails.

Any ideas as to what I'm missing here?

Any help much appreciated!

Artie


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spr_myStoredProc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spr_myStoredProc]
GO

CREATE PROCEDURE [dbo].[spr_myStoredProc] AS

DECLARE @stat     int

BEGIN

DELETE
FROM dbo.tbl_myTable

SET @stat=@@ERROR
IF @@ERROR <> 0 GOTO finish

-- other stuff edited out to narrow down the nant sql error

finish:

RETURN @stat
END

Re: NAnt sql task fails, but code works in SQL Query Analyzer

by Bob Archer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Put a GO at the end of the file. I think that might resolve it.

BOb


-----Original Message-----
From: Artie Leech [mailto:artieleech@...]
Sent: Thursday, October 02, 2008 6:34 AM
To: nant-users@...
Subject: [NAnt-users] NAnt sql task fails, but code works in SQL Query
Analyzer


Hi,

I'm trying to create a nant task that will build my database, which uses
SQL
Server 2000.

I have the following line in a loop to load up a number of stored procs.

<sql connstring="${database.project.connstring}" delimiter="GO"
transaction="true" batch="false" delimstyle="Normal"
source="${database.ddl.filename}"/>

It's trying to load the stored proc code shown at the bottom of this
post.

When I run my nant task, I get the following error:


"BUILD FAILED - 2 non-fatal error(s), 0 warning(s)
default.build(52,22):
Error while executing SQL statement.
    Object reference not set to an instance of an object."

However, if I remove the line "IF @@ERROR <> 0 GOTO finish", from the
code
below, then the build succeeds.

Loading the proc through SQL Server Query Analyzer works fine - it's
just
from the NAnt sql task it fails.

Any ideas as to what I'm missing here?

Any help much appreciated!

Artie


if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[spr_myStoredProc]') and OBJECTPROPERTY(id,
N'IsProcedure') = 1)
drop procedure [dbo].[spr_myStoredProc]
GO

CREATE PROCEDURE [dbo].[spr_myStoredProc] AS

DECLARE @stat     int

BEGIN

DELETE
FROM dbo.tbl_myTable

SET @stat=@@ERROR
IF @@ERROR <> 0 GOTO finish

-- other stuff edited out to narrow down the nant sql error

finish:

RETURN @stat
END

--
View this message in context:
http://www.nabble.com/NAnt-sql-task-fails%2C-but-code-works-in-SQL-Query
-Analyzer-tp19776861p19776861.html
Sent from the NAnt - Users mailing list archive at Nabble.com.


------------------------------------------------------------------------
-
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@...
https://lists.sourceforge.net/lists/listinfo/nant-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@...
https://lists.sourceforge.net/lists/listinfo/nant-users

Re: NAnt sql task fails, but code works in SQL Query Analyzer

by Artie Leech :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Bob,

I tried putting a GO at the end, but I still get the same error.  Any other ideas?

Thanks,

Artie
Bob Archer wrote:
Put a GO at the end of the file. I think that might resolve it.

BOb


-----Original Message-----
From: Artie Leech [mailto:artieleech@yahoo.co.uk]
Sent: Thursday, October 02, 2008 6:34 AM
To: nant-users@lists.sourceforge.net
Subject: [NAnt-users] NAnt sql task fails, but code works in SQL Query
Analyzer


Hi,

I'm trying to create a nant task that will build my database, which uses
SQL
Server 2000.

I have the following line in a loop to load up a number of stored procs.

<sql connstring="${database.project.connstring}" delimiter="GO"
transaction="true" batch="false" delimstyle="Normal"
source="${database.ddl.filename}"/>

It's trying to load the stored proc code shown at the bottom of this
post.

When I run my nant task, I get the following error:


"BUILD FAILED - 2 non-fatal error(s), 0 warning(s)
default.build(52,22):
Error while executing SQL statement.
    Object reference not set to an instance of an object."

However, if I remove the line "IF @@ERROR <> 0 GOTO finish", from the
code
below, then the build succeeds.

Loading the proc through SQL Server Query Analyzer works fine - it's
just
from the NAnt sql task it fails.

Any ideas as to what I'm missing here?

Any help much appreciated!

Artie


if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[spr_myStoredProc]') and OBJECTPROPERTY(id,
N'IsProcedure') = 1)
drop procedure [dbo].[spr_myStoredProc]
GO

CREATE PROCEDURE [dbo].[spr_myStoredProc] AS

DECLARE @stat     int

BEGIN

DELETE
FROM dbo.tbl_myTable

SET @stat=@@ERROR
IF @@ERROR <> 0 GOTO finish

-- other stuff edited out to narrow down the nant sql error

finish:

RETURN @stat
END

--
View this message in context:
http://www.nabble.com/NAnt-sql-task-fails%2C-but-code-works-in-SQL-Query
-Analyzer-tp19776861p19776861.html
Sent from the NAnt - Users mailing list archive at Nabble.com.


------------------------------------------------------------------------
-
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Re: NAnt sql task fails, but code works in SQL Query Analyzer

by Bob Archer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's because [I think] you are using "Normal" delimiter. So, it sees GO
in the word GOTO and assumes that is the end of the block and sends that
to SQL. Can you change to use Line delimiter and make sure all your GO's
are on their own line?

BOb


-----Original Message-----
From: Artie Leech [mailto:artieleech@...]
Sent: Thursday, October 02, 2008 10:56 AM
To: nant-users@...
Subject: Re: [NAnt-users] NAnt sql task fails, but code works in SQL
Query Analyzer


Hi Bob,

I tried putting a GO at the end, but I still get the same error.  Any
other
ideas?

Thanks,

Artie

Bob Archer wrote:

>
> Put a GO at the end of the file. I think that might resolve it.
>
> BOb
>
>
> -----Original Message-----
> From: Artie Leech [mailto:artieleech@...]
> Sent: Thursday, October 02, 2008 6:34 AM
> To: nant-users@...
> Subject: [NAnt-users] NAnt sql task fails, but code works in SQL Query
> Analyzer
>
>
> Hi,
>
> I'm trying to create a nant task that will build my database, which
uses
> SQL
> Server 2000.
>
> I have the following line in a loop to load up a number of stored
procs.

>
> <sql connstring="${database.project.connstring}" delimiter="GO"
> transaction="true" batch="false" delimstyle="Normal"
> source="${database.ddl.filename}"/>
>
> It's trying to load the stored proc code shown at the bottom of this
> post.
>
> When I run my nant task, I get the following error:
>
>
> "BUILD FAILED - 2 non-fatal error(s), 0 warning(s)
> default.build(52,22):
> Error while executing SQL statement.
>     Object reference not set to an instance of an object."
>
> However, if I remove the line "IF @@ERROR <> 0 GOTO finish", from the
> code
> below, then the build succeeds.
>
> Loading the proc through SQL Server Query Analyzer works fine - it's
> just
> from the NAnt sql task it fails.
>
> Any ideas as to what I'm missing here?
>
> Any help much appreciated!
>
> Artie
>
>
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[spr_myStoredProc]') and OBJECTPROPERTY(id,
> N'IsProcedure') = 1)
> drop procedure [dbo].[spr_myStoredProc]
> GO
>
> CREATE PROCEDURE [dbo].[spr_myStoredProc] AS
>
> DECLARE @stat     int
>
> BEGIN
>
> DELETE
> FROM dbo.tbl_myTable
>
> SET @stat=@@ERROR
> IF @@ERROR <> 0 GOTO finish
>
> -- other stuff edited out to narrow down the nant sql error
>
> finish:
>
> RETURN @stat
> END
>
> --
> View this message in context:
>
http://www.nabble.com/NAnt-sql-task-fails%2C-but-code-works-in-SQL-Query
> -Analyzer-tp19776861p19776861.html
> Sent from the NAnt - Users mailing list archive at Nabble.com.
>
>
>
------------------------------------------------------------------------

> -
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> NAnt-users mailing list
> NAnt-users@...
> https://lists.sourceforge.net/lists/listinfo/nant-users
>
>
------------------------------------------------------------------------
-

> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> NAnt-users mailing list
> NAnt-users@...
> https://lists.sourceforge.net/lists/listinfo/nant-users
>
>

--
View this message in context:
http://www.nabble.com/NAnt-sql-task-fails%2C-but-code-works-in-SQL-Query
-Analyzer-tp19776861p19780945.html
Sent from the NAnt - Users mailing list archive at Nabble.com.


------------------------------------------------------------------------
-
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@...
https://lists.sourceforge.net/lists/listinfo/nant-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@...
https://lists.sourceforge.net/lists/listinfo/nant-users

Re: NAnt sql task fails, but code works in SQL Query Analyzer

by Artie Leech :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bob,

You're right! In the sql task, changing from

delimstyle="Normal"
to
delimstyle="Line"

sorted my problem.

As you said, I just need to ensure all my 'GO's are on their own line now.

Thanks very much indeed for you help.

Artie

Bob Archer wrote:
It's because [I think] you are using "Normal" delimiter. So, it sees GO
in the word GOTO and assumes that is the end of the block and sends that
to SQL. Can you change to use Line delimiter and make sure all your GO's
are on their own line?

BOb


-----Original Message-----
From: Artie Leech [mailto:artieleech@yahoo.co.uk]
Sent: Thursday, October 02, 2008 10:56 AM
To: nant-users@lists.sourceforge.net
Subject: Re: [NAnt-users] NAnt sql task fails, but code works in SQL
Query Analyzer


Hi Bob,

I tried putting a GO at the end, but I still get the same error.  Any
other
ideas?

Thanks,

Artie

Bob Archer wrote:
>
> Put a GO at the end of the file. I think that might resolve it.
>
> BOb
>
>
> -----Original Message-----
> From: Artie Leech [mailto:artieleech@yahoo.co.uk]
> Sent: Thursday, October 02, 2008 6:34 AM
> To: nant-users@lists.sourceforge.net
> Subject: [NAnt-users] NAnt sql task fails, but code works in SQL Query
> Analyzer
>
>
> Hi,
>
> I'm trying to create a nant task that will build my database, which
uses
> SQL
> Server 2000.
>
> I have the following line in a loop to load up a number of stored
procs.
>
> <sql connstring="${database.project.connstring}" delimiter="GO"
> transaction="true" batch="false" delimstyle="Normal"
> source="${database.ddl.filename}"/>
>
> It's trying to load the stored proc code shown at the bottom of this
> post.
>
> When I run my nant task, I get the following error:
>
>
> "BUILD FAILED - 2 non-fatal error(s), 0 warning(s)
> default.build(52,22):
> Error while executing SQL statement.
>     Object reference not set to an instance of an object."
>
> However, if I remove the line "IF @@ERROR <> 0 GOTO finish", from the
> code
> below, then the build succeeds.
>
> Loading the proc through SQL Server Query Analyzer works fine - it's
> just
> from the NAnt sql task it fails.
>
> Any ideas as to what I'm missing here?
>
> Any help much appreciated!
>
> Artie
>
>
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[spr_myStoredProc]') and OBJECTPROPERTY(id,
> N'IsProcedure') = 1)
> drop procedure [dbo].[spr_myStoredProc]
> GO
>
> CREATE PROCEDURE [dbo].[spr_myStoredProc] AS
>
> DECLARE @stat     int
>
> BEGIN
>
> DELETE
> FROM dbo.tbl_myTable
>
> SET @stat=@@ERROR
> IF @@ERROR <> 0 GOTO finish
>
> -- other stuff edited out to narrow down the nant sql error
>
> finish:
>
> RETURN @stat
> END
>
> --
> View this message in context:
>
http://www.nabble.com/NAnt-sql-task-fails%2C-but-code-works-in-SQL-Query
> -Analyzer-tp19776861p19776861.html
> Sent from the NAnt - Users mailing list archive at Nabble.com.
>
>
>
------------------------------------------------------------------------
> -
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> NAnt-users mailing list
> NAnt-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nant-users
>
>
------------------------------------------------------------------------
-
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> NAnt-users mailing list
> NAnt-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nant-users
>
>

--
View this message in context:
http://www.nabble.com/NAnt-sql-task-fails%2C-but-code-works-in-SQL-Query
-Analyzer-tp19776861p19780945.html
Sent from the NAnt - Users mailing list archive at Nabble.com.


------------------------------------------------------------------------
-
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users
LightInTheBox - Buy quality products at wholesale price!