Running script issue with TADOQuery

I'm currently use Delphi 7's TADOQuery connected to MS Server 2005/2008 to run scripts.  The scripts are stored in a *.SQL file.  I extract the text and load into the SQL.Text property.  I'm getting an error running running the script:

Error running script C:\Program Files\TSS\TitleExpress\DB Scripts\OMSQL_Add.sql; Error = Access violation at address 000EFD24. Write of address 000EFD24	8:36:21 AM

The *.SQL file contains multiple statements.  It creates a database, adds tables to it, and sets up some users.  The statements are generated from SSMS directly, so they have semicolons and GO statements throughout.  This script runs fine if run directly from MS Server's SSMS.  Here is my code snippet (GetSQLFileText returns a TStringList):

***************************************
  conn := TADOConnection.Create(nil);
  try
    try
      conn.ConnectionString := str;
      conn.KeepConnection := true;
      conn.Mode := cmReadWrite;
      conn.LoginPrompt := false;
      conn.Open();

      if (conn.Connected) then
      begin
        DbugIntf.SendDebug('Connected to DB');

        qry := TADOQuery.Create(nil);
        qry.Connection := conn;

        qry.SQL.Clear;
        qry.SQL.Text := GetSQLFileText(SQLFile).Text;
        qry.ExecSQL;
        DbugIntf.SendDebug('Script ' + SQLFile + 'ran sucessfully');
      end;
    except on E:Exception do
    begin
      DbugIntf.SendDebug('Error executing script ' + SQLFile + '; Error = ' + E.Message);
      result := 8;
    end;
  end;
  finally
    if (Assigned(conn) and conn.Connected) then
      conn.Connected := false;
  end;
***************************************

Thanks in advance for any assistance
Matt
0
Matt
12/12/2008 3:09:28 PM
embarcadero.delphi.ado 597 articles. 1 followers. Follow

4 Replies
968 Views

Similar Articles

[PageSpeed] 37

Hi,

FWIW, i have never had any luck running multiple batch sql files using any 
of the TADO components. In the end i had to execute sqlcmd putting together 
a command line and executing the script that way.

Hth,

Brian
0
Brian
12/12/2008 3:26:23 PM
Matt Bond wrote:
>         qry.SQL.Text := GetSQLFileText(SQLFile).Text;

I suspect that this line is your problem. If GetSQLFileText returns nil, 
this will cause an access violation. Can you step through your code and 
see which line causes the exception?

As a side-note, it also looks like this line may cause a memory leak if 
GetSQLFileText *doesn't* return nil. Is this function supposed to be 
responsible for freeing the TStringList that is returned?

-Mike
0
Mike
12/12/2008 7:45:22 PM
Brian Hollister wrote:
> FWIW, i have never had any luck running multiple batch sql files using any 
> of the TADO components.

Likewise. ADO didn't seem to like the GO command when I tried it. I 
ended up writing a function to split the text up into individual 
statements, then doing an ExecSQL for each one.

-Mike
0
Mike
12/12/2008 7:48:54 PM
Matt Bond wrote:

> 'm currently use Delphi 7's TADOQuery connected to MS Server
> 2005/2008 to run scripts.

Use TAdoCommand component instead.  

-- 
Iman
0
Iman
12/15/2008 2:29:44 AM
Reply:

Similar Artilces:

Convert Delphi 5 ADO App to Delphi 2007 ADO.NET
I have an appliction tha that is writen in Delphi 5 with ADOConnetion, ADOTable, and ADOQuery components. I need to upgrade to Delphi 2007 and use ADO.NET. I have the program building in with Delphi 2007. Is there anything I need to do to convert the ADO to ADO.NET? > I need to upgrade to Delphi 2007 and use ADO.NET. Why ? -- With best regards, Dmitry Arefiev AnyDAC (www.anydac.com) - Oracle, MS SQL Server, IBM DB2, MySQL, Firebird, Interbase, PostgreSQL, Sybase ASA, SQLite, MS Access, DBX, ODBC, InMem - universal high-speed native data access engine Reasons for ...

yield the running of current window script to allow to run other windows script
Hello, I have two windows opened.I would like to suspend the runing of one window script so that other window script can be run.I am just wondeing is there any way to do the same. Thanks, Sri. Yield(); On May 20, 7:06=A0am, sr.100...@gmail.com wrote: > Hello, > > =A0 I have two windows opened.I would like to suspend the runing of one > window script so that other window script can be run.I am just > wondeing is there any way to do the same. > > Thanks, > Sri. ...

I have a weird issue with a script running under cron
I get the following error: install_driver(Oracle) failed: Can't load '/usr/local/lib64/perl5/auto/DBD/= Oracle/Oracle.so' for module DBD::Oracle: libocci.so.11.1: cannot open shar= ed object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm= line 200, <DATA> line 749. at (eval 10) line 3 Compilation failed in require at (eval 10) line 3, <DATA> line 749. Perhaps a required shared library or dll isn't installed where expected at /home/allwebfiles/perl/kfs/kfsupdate.pl line 21 The script runs just fine when run interactively in a shell. ...

A serious error in running scripts from delphi.
Hi all. I have a serious problem using Delphi 7 and sqlserver2000. I want to run some scripts by AdoConnection.Execute and I want them all to run together(like a Bath). But when I run my program and detect it with SQLProfiler I see that each line of my scripts is runned in a block of login-logout and I don't know why. I think this situation only accurs if we have a open query on the server.it means we have an adoquery with server cursor-location that open a cursor on the server.after that when we have some scripts in the way I described earlier, we have an error. Look at the simplif...

is it possible to run apple script in delphi FM2
I want to run an apple script with FM2 is it possible . if it is please tell me how > I want to run an apple script with FM2 > is it possible . if it is please tell me how What is it you're trying to do exactly? If it's just run an arbitary script that has no particular connection to the application itself, it should be doable if you declare your own interface declarations for relevant Cocoa types. ...

Running Running Running
Name: John Harris Email: jkharrisatmindspringdotcom Product: Firefox Summary: Running Running Running Comments: Why, does Firefox, even when mimimized, still takes up to 20, 30, 40% (or more) of my CPU on my Windows XP Pro computer. It seems to just happily chew up cycles. How do I get it to do nothing while minimized. Especially a problem with virtual machines. Thanks, John Harris Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729) From URL: http://hendrix.mozilla.org/ Note to readers...

Running script in another script
Hi, Can I executed JavaScriptScript in another JavaScript having different JSContext. I am using spidermonkey with JS_THREADSAFE and protecting code with JS_BegineRequest etc. Will there be any threading issues like deadlocks. I am also calling JS_GC() after the script is executed. Manoj ...

Running Power Shell scripts suing VB Script by Script Driver
Hi, I am having IDM 3.5 installed. I want to provision exchange account with the help of Power Shell scripts executed by VB Scripts by Script Driver. (not provisioning exchg accounts thru AD driver-thats my requirement). In this scenario, I have the working power shell script like given below. My question is: 1. How do I execute this Power shell script from the Scripting Driver (thru vb script)? 2. How do I create scripting driver and how do I communicate driver to exchng server? 3. Where do I place this Power Shell script and call this? POWERSHELL SCRIPT: $PASS = READ-HO...

Netware scripting issue
I'm having trouble getting started with scripting on netware. (nw6.5sp4) I need to be able to use cron to schedule 3 rsync processes but I don't know how long they will take and I don't want them running together. Basically I want any method at all of being able to start rsync then start another when the first has finished. I thought it would be simple to use perl but find that the syntax that works to "execute a command and wait" on perl for linux or windows does not not work for me on netware: $result = `ext_command` #uses backticks with this method...

VBscript run as a Run before Distribution script
I have a VB script that I want to run as a Run before Distribution script. All my attempts have failed. Any suggestions on how to accomplish this?? cupps@trinity-health.org, > > I have a VB script that I want to run as a Run before Distribution > script. All my attempts have failed. Any suggestions on how to > accomplish this?? What code version are you running? -- Jared L Jennings Novell Support Forums SysOp Systems Engineer for Data Technique, INC. ICQ# 27902780 Using XanaNews 1.16.3.1 ...

Run master script before page script
Hi,I'm looking for a way of running the Page_Load subroutine in my .master file before the one in the .aspx file. This is because in my .master file I have an If statement which redirects the user to a login page if a cookie doesn't exist. However because the .aspx file is ran first, it produces an error when the cookie is referred to. Is there a way of doing this?Thanks for your help. Regards, Curt you cant change the sequence of the events.  Try using the Init event in the master page check this for the sequence: http://forums.asp.net/t/1191194.aspxMike Banavige~~~~~~~...

Make a script to run multiple scripts
--B_3405587943_12541884 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Hi all, I have 7 perl scripts that I want to run simultaneously from the command line with the possibility of growing this number. I'm pretty new to perl, so thought in the mean time it would be a good idea to create a perl script to run multiple scripts. I could just add to this file as needed if more scripts are created. What is the best way to do this? I have the following scripts that I want to fire off all at once. attachment.pl attachment2.pl attachment3....

Scripting driver fail to run script
Hi All, I am trying to run a scripting driver, but ... As soon as the event hits the system and tries to create a tempory file i get : In the trace logging on the IV : Message: Error creating temporary file for object \SBH_MD\HSB\Users\user1 (code 183). Event discarded. And in the Remote loader logging : 2009-07-21 17:13:18 [5236@4364] (trace): WindowsScript addHandler creating input document 2009-07-21 17:13:18 [5236@4364] (trace): C:\WINDOWS\TEMP\WSD3DD.tmp 2009-07-21 17:13:18 [5236@4364] (trace): Couldn't create event file C:\WINDOWS\TEMP\WSD3DD.tmp: err...

Running a .VBS script from a logon script
Guys, Is there a way to run a .vbs script direct from a Novell 6.0 logon script without having to use a batch file (.BAT)? If not is there a way to run a batch file hidden or minimized from the logon script? whick then runs the .VBS script? I cannot seem to get my batch file to run minimized on XP? Clients PC are mainly XP but we do have about 150 Windows 98 laptops. Rgds Mark Burse > I cannot seem to get my batch file to run minimized on XP? START /MIN does not work ? -- Edison Ortiz Novell Product Support Forum SysOp (No Email Support, Thanks !) Mark, ...

Web resources about - Running script issue with TADOQuery - embarcadero.delphi.ado

Resources last updated: 12/2/2015 10:23:10 PM