473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Running an entire SQL Script from C#

Hi

I have written a small transformation routine that converts my XML file into
a bunch of Insert statements in another file. The file will be in the
following format but much longer:

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('lasfgasd ');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('afgsasg');

How can I possibly run this entire script from inside of my script???
Assuming I can already make my connection to the SQL Server Database.
Nov 29 '05 #1
7 1452
Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
Hi

I have written a small transformation routine that converts my XML file
into
a bunch of Insert statements in another file. The file will be in the
following format but much longer:

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('lasfgasd ');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('afgsasg');

How can I possibly run this entire script from inside of my script???
Assuming I can already make my connection to the SQL Server Database.

Nov 29 '05 #2

I'm sorry if this is a simple question.. but how do I append them all into
on string?
and is that the only way? is there no way of committing or executing a
script (*.sql)?
"Martin Robins" wrote:
Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
Hi

I have written a small transformation routine that converts my XML file
into
a bunch of Insert statements in another file. The file will be in the
following format but much longer:

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('lasfgasd ');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('afgsasg');

How can I possibly run this entire script from inside of my script???
Assuming I can already make my connection to the SQL Server Database.


Nov 30 '05 #3
Yes you could use a StreamReader to read the sql from the file and then
set it as the commandText of the Command object.

Simon

farsad nasseri wrote:
I'm sorry if this is a simple question.. but how do I append them all into
on string?
and is that the only way? is there no way of committing or executing a
script (*.sql)?
"Martin Robins" wrote:

Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@micros oft.com...
Hi

I have written a small transformation routine that converts my XML file
into
a bunch of Insert statements in another file. The file will be in the
following format but much longer:

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('lasfgasd ');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('afgsasg');

How can I possibly run this entire script from inside of my script???
Assuming I can already make my connection to the SQL Server Database.


Nov 30 '05 #4
Hi,
You do not need to run it as a single script, at least the snip you gave,
you could just simply execute it one by one, of course the performance will
be lower than if you concatenate all the script in a single string and pass
it to the server.

Now if you have a REAL big script ( like 10K inserts ) having it as a
single command is not practical.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
Hi

I have written a small transformation routine that converts my XML file
into
a bunch of Insert statements in another file. The file will be in the
following format but much longer:

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('lasfgasd ');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('afgsasg');

How can I possibly run this entire script from inside of my script???
Assuming I can already make my connection to the SQL Server Database.

Nov 30 '05 #5
Listen that is really uncalled for take a chill pill man.

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community
Nov 30 '05 #6
> Listen that is really uncalled for take a chill pill man.

I agree. Whoever the heck it is you're talking to, whatever the heck you're
talking about, he or she should take a chill pill. Seriously. Dude.

--

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"ship261" <st*****@m-s-n-dot-net.no-spam.invalid> wrote in message
news:l8********************@giganews.com...
Listen that is really uncalled for take a chill pill man.

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community

Nov 30 '05 #7
Yup I have to agree .. no idea what your talking about .. hehe

Reply to wrong thread me thinks ;)

ship261 wrote:
Listen that is really uncalled for take a chill pill man.

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community

Dec 1 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sticks | last post by:
ok... im not quite sure how to describe my problem. i have a php script that runs through my entire php site and writes the resulting output to html files. this is necessary as the nature of the...
1
by: Andrew Chalk | last post by:
I am developing a CGI app, When the user loads my page I want to populate an HTML 'select' box (drop down menu) with items from a database. What is the best way to get my Python procedure that does...
5
by: code_wrong | last post by:
Hi Firefox does not support the IE specific 'event' identifier and just quits running the script. ..... even though the identifier only turns up in code marked for IE only ... Does this seem...
12
by: Troy | last post by:
My ISP provides me with 2 servers: one for normal web hosting (non-PHP) and a CGI server (with PHP). I create my website using fusion 7 and upload this in its entirity to the web hosting server....
0
by: Titof | last post by:
Hello, i want to create an active webpage that displays the status of users quotas on a volume of a server. I installed IIS on this server and installed Win2k server Resource Kit because the...
2
by: Benjamin Rutt | last post by:
I often execute a long-running python script which is a "driver" for my application; it may run for several hours on a large input. Under CPython, is it safe for me to modify the Python script...
13
by: wattersmt | last post by:
Hello, I am trying to write a python cgi that calls a script over ssh, the problem is the script takes a very long time to execute so Apache makes the CGI time out and I never see any output. ...
24
by: Mark | last post by:
Hi, I'm new to python and looking for a better idiom to use for the manner I have been organising my python scripts. I've googled all over the place about this but found absolutely nothing. I'm...
22
by: V S Rawat | last post by:
(bringing the discussion here for php.general) I am on xpsp3, wampserver 2.0, having apache 2.2.8, php 5.2.6, MySQL 5.0.51b. http://localhost/ is E:\wamp\www\ I have put the first php script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.