Execute a .SQL File

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my application, i get datas that i put in a .SQL f.ile

I would like to execute this file for integrate the data onto a Sql Server
database.

I know that i can parse the file line by line for executing the SQL
commandes, but i would like to know if there was no better way ?

I've look at the CommandType enumeration, without success

Have you got an idea ?

Thank you
 
Lebrun Thomas said:
In my application, i get datas that i put in a .SQL f.ile

I would like to execute this file for integrate the data onto a Sql Server
database.

I have had good luck simply reading the SQL as CommandText, and then using
ExecuteNonQuery. I am not sure about a size limitation this way, though.
Haven't tried it on more than about 50,000 rows.

Best Regards,

Andy
 
Curently; i'm trying to retrieve all the content of the SQL file with a
streamreader

sr.ReadToEnd()

and after that, i put

sFile = sr.ReadToEnd();
SQLCommande.CommandText = sFile;


but i've got errors...
 
Do you have GO statements in your SQL contents. If you do you will have to
parse the file and send each batch for execution.

Lloyd Sheen
 
Couldn't you just use the Process class to start osql with the proper
command line params?

----- Original Message -----
From: "Lebrun Thomas" <lebrun_thomas_at_hotmail.com>
Newsgroups: microsoft.public.dotnet.framework
Sent: Thursday, August 05, 2004 4:03 PM
Subject: Execute a .SQL File
 
Ok, the errors are solved by deleteing the GO statement.

But i don't like the way i proceed : a streamreader) : i don't find this as
very professionnal....

But it work :)

Bye.
 
Lebrun Thomas said:
Ok, the errors are solved by deleteing the GO statement.

But i don't like the way i proceed : a streamreader) : i don't find this as
very professionnal....

What's wrong with using a StreamReader? It's absolutely the right way
to go when you're reading a text file.

To be honest, your current way sounds fine to me.
 
Couldn't you just use the Process class to start osql with the proper
command line params?

I need to give a try to this

Thank you

--
LEBRUN Thomas
http://morpheus.developpez.com


Peter Vervoorn said:
Couldn't you just use the Process class to start osql with the proper
command line params?

----- Original Message -----
From: "Lebrun Thomas" <lebrun_thomas_at_hotmail.com>
Newsgroups: microsoft.public.dotnet.framework
Sent: Thursday, August 05, 2004 4:03 PM
Subject: Execute a .SQL File
 
What's wrong with using a StreamReader? It's absolutely the right way
to go when you're reading a text file.

To be honest, your current way sounds fine to me.

Yes, i know : but as it's possible to execute a stord procedure, i thought
there was a way to execute a sql file :)
 
Lebrun Thomas said:
Yes, i know : but as it's possible to execute a stord procedure, i thought
there was a way to execute a sql file :)

Executing a string is far more general than executing a file. I don't
imagine that comes up very often as a requirement, and is so easy to
implement on top of executing a generic string, that it's not worth
putting in the framework.
 
Lebrun Thomas said:
I need to give a try to this

That is really the best way, if you are using SQL Server and have the client
tools installed. My personal favorite.

Best Regards,

Andy
 
Back
Top