G
Gislain
Hi,
I'm trying to run .sql file with C# code, but i have systematically an error
message with the "GO" instruction. When i test the script in SQL Server
Management Studio, it work fine !!!
First part of the error message
----------------------------------------
{System.Data.SqlClient.SqlException: Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection)
etc...
SQL file to be played (SET NOEXEC ON is needed !!!)
--------------------------------------------------------------------------------
SET NOEXEC ON
GO
DROP PROCEDURE spr_gr_test
GO
CREATE PROCEDURE spr_gr_test
as
begin
PRINT 'titi'
end
GO
C# code
----------------------------------------
SqlCommand __cmd = myConnection.CreateCommand();
StreamReader __streamReader = null;
string __myQuery = "";
int __rc = 0;
try
{
__streamReader = new
StreamReader(@"C:\Data\Dvlp\SQL.2005\CheckScript\SQLQuery1.sql");
__myQuery = __streamReader.ReadToEnd();
__cmd.CommandType = CommandType.Text;
__cmd.CommandText = __myQuery;
__rc = __cmd.ExecuteNonQuery();
Debug.WriteLine(__rc.ToString());
}
catch (Exception exp)
{
Debug.WriteLine(exp.ToString());
}
finally
{
if (__streamReader != null)
__streamReader.Close();
}
Where is the solution ?
Where is the mistake .....
Thank's by advance
Gislain
I'm trying to run .sql file with C# code, but i have systematically an error
message with the "GO" instruction. When i test the script in SQL Server
Management Studio, it work fine !!!
First part of the error message
----------------------------------------
{System.Data.SqlClient.SqlException: Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection)
etc...
SQL file to be played (SET NOEXEC ON is needed !!!)
--------------------------------------------------------------------------------
SET NOEXEC ON
GO
DROP PROCEDURE spr_gr_test
GO
CREATE PROCEDURE spr_gr_test
as
begin
PRINT 'titi'
end
GO
C# code
----------------------------------------
SqlCommand __cmd = myConnection.CreateCommand();
StreamReader __streamReader = null;
string __myQuery = "";
int __rc = 0;
try
{
__streamReader = new
StreamReader(@"C:\Data\Dvlp\SQL.2005\CheckScript\SQLQuery1.sql");
__myQuery = __streamReader.ReadToEnd();
__cmd.CommandType = CommandType.Text;
__cmd.CommandText = __myQuery;
__rc = __cmd.ExecuteNonQuery();
Debug.WriteLine(__rc.ToString());
}
catch (Exception exp)
{
Debug.WriteLine(exp.ToString());
}
finally
{
if (__streamReader != null)
__streamReader.Close();
}
Where is the solution ?
Where is the mistake .....
Thank's by advance
Gislain