473,480 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Running SQL Script from in a program.

Hi C# users;
I am trying to run an SQL Script on an Access database. I can do it
directly, but, what I would like to do is build a dll that I can call and
give it the databasename and the SQLScript filename and have it return an
integer for success or failure.

Example: int ExecuteSqlScript(string databasePathName, string script);

If you have any ideas I would be gratefull
Thanks.
Rich III
Nov 16 '05 #1
2 1336
All you need to do is have the first parameter specify a valid connection
string, then thesecond one a valid command.

Then you can just use a OleDbCommand object, using a connection created
fromthe String. YOu can just specify the commandtext property of the
command to be the script. From there, you can call ExecuteNonQuery to fire
it.

Since you're using Access and not Sql Server, you'd need to do some
translating, but you could take a look at Microsoft's Data Access
Applicaiton Block to get an idea about how this works in more complex
scenarios - but in the simplest form - all you'd need to do is what I
mentioned above.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Rich III" <Ri*****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
Hi C# users;
I am trying to run an SQL Script on an Access database. I can do it
directly, but, what I would like to do is build a dll that I can call and
give it the databasename and the SQLScript filename and have it return an
integer for success or failure.

Example: int ExecuteSqlScript(string databasePathName, string script);

If you have any ideas I would be gratefull
Thanks.
Rich III

Nov 16 '05 #2
Rich,

That should be easy enough. Basically, you would load the contents of
the file into a string, and then set that string to a command (OleDbCommand
in the case of Access) object. The connection for the object (an
OleDbConnection) would be set with the provider for Access, as well as the
path (you would construct the whole thing dynamically). Then, all you have
to do is execute it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rich III" <Ri*****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
Hi C# users;
I am trying to run an SQL Script on an Access database. I can do it
directly, but, what I would like to do is build a dll that I can call and
give it the databasename and the SQLScript filename and have it return an
integer for success or failure.

Example: int ExecuteSqlScript(string databasePathName, string script);

If you have any ideas I would be gratefull
Thanks.
Rich III

Nov 16 '05 #3

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

Similar topics

1
10278
by: Hal Vaughan | last post by:
I'm having trouble with a bash script (in Linux) I'm running from Java. It works -- some of the time, but I can't determine exactly why it works 1 time and doesn't work the next 4-5 times. I'm...
5
5292
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
6
10499
by: Pierre-Yves | last post by:
Hello, I would like to prevent my perl program to be executed several times simultaneously (if the program is already running, I would like to display a message like "another instance of this...
8
2750
by: Jonathan Heath | last post by:
Hi all, I have created an ASP script that enters data into an Access Database. My problem is that I'd like this script to run when the computer is shutdown or the user logs off. I think...
4
5983
by: Nick Sinclair | last post by:
Hi all, I'm new to C. I have successfully written a small C program that acts as a "wrapper" around cgi scripts. These scripts perform admin tasks such as backing up etc. Obviously, The need...
0
1326
by: joeted | last post by:
Hi, I am using system.diagnostic.process with the intention of running a program to communicate with a unix box: The program is "PuTTY", running from a batch script. I know it works because...
3
4105
by: sir.linying | last post by:
My php script is to call perl scipt which makes use of Spreadsheet::ParseExcel module to parse Excel file. I am able to launch php script from command line so that perl script can run and properly...
51
4075
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
3
3684
by: WP | last post by:
Hello, I have a very simple script (or would you call it a batch file?) with the following content: connect to mydb2; DROP TABLE staff_employee_address; DROP TABLE...
5
2532
by: Christopher Brewster | last post by:
I am running the same script on the same data on two different machines (the folder is synchronised with Dropbox). I get two different results. All the script does is count words in different...
0
6908
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...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.