New Message on dotNET User Group Hyd

running .sql file using C#

Reply
  Reply to Sender   Recommend Message 1 in Discussion
From: Deeps2808

Hi all
 
 I have a .sql ..which is not a stored proc , but kind of few sql cmnds and then a stored proc also...
 
I want to read tht sql file in my C# code and execute it.
My code looks like this....

FileStream file=new FileStream("Filename.sql",System.IO.FileMode.Open);

StreamReader sr=new StreamReader(file);

string str_create=sr.ReadToEnd();

sr.Close();

file.Close();

SqlCommand sp_createcmd=new SqlCommand(str_create,conn);

conn.Open();

sp_createcmd.ExecuteNonQuery();

conn.Close();

....This code is giving me exceptions in the .sql file...........
 
My sql file looks like this......
 
USE Performance
GO
if exists (select * from sysobjects where id =
        object_id(N'[dbo].[AddEvent]') and OBJECTPROPERTY(id, N'IsProcedure') =
1)
drop procedure [dbo].[AddEvent]
GO
USE Performance
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
 
CREATE   PROC dbo.AddEvent
(
 @TraceID int,
 @EventList varchar(1000),
 @ColumnList varchar(1000) = NULL
)
AS
BEGIN
 CREATE TABLE #EventList
 (
.....................etc etc../.
 
So my C# code gives me exceptions like Create PROC shd be the first like...etc.etc..
It seems its trying to run this as an stored proc....I cannot change my stored proc code....so How do i execute this then...
Any help would be gr8ly appreciated
 
Thanks,
Deeps

View other groups in this category.


Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to