Solved

Running SQL Scripts

Posted on 2001-07-18
7
984 Views
Last Modified: 2012-06-27
We are deploying an application based on MSDE.  I would like to store the database creation and generation details in SQL Script files.  This is an easy solution with SQL Server because I can simply run the scripts from the command line in the installation with the ISQL tool. (Note, I can't use an interactive solution because from the user's standpoint, the database create's itself on install).  The problem is now the solution is based on MSDE, which I am not entirely sure if ISQL (not ISQL/w) is deployed with MSDE.  If it is not, is it redistributable.  If it is not redistributable, does anybody have some good ADO code samples to read an SQL script that uses the same syntax as ISQL.  What I mean by syntax, is support for the "USE <DATABASENAME>" and Go command?
0
Comment
Question by:bequette
7 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6294026
If you have access to the SQL-DMO object libraries then you can use the following to achieve this:

 Dim sqlServer As SQLDMO.sqlServer
  Set sqlServer = New SQLDMO.sqlServer
  sqlServer.Connect "MySQLServer"
  sqlServer.Databases("MyDatabase").ExecuteImmediate Replace(strBatch,"GO",vbCRLF & "GO" & vbCRLF), SQLDMOExec_ContinueOnError
  sqlServer.DisConnect
  Set sqlServer = Nothing

Where strBatch contains the sql batch that you want to run.
0
 
LVL 2

Expert Comment

by:agriggs
ID: 6298286
I am pretty sure that SQL-DMO is installed when you install the SQL Client tools, like ISQL.

I think that you are on the right track when you say you need to read the scripts into an ADO project and then execute them.

GO is not a SQL keyword, it is an ISQL keyword that means just what it says.  So whenever you encounter a GO in your scripts, just execute your SQL string.
0
 
LVL 1

Expert Comment

by:lindr
ID: 6302125
You should be able to use the command line version (OSQL) which I think is shipped with MSDE.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Expert Comment

by:CleanupPing
ID: 9282025
bequette:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 9286100
I'll register an interest!
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9623207
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Award points to TimCottee

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Anthony
EE Cleanup Volunteer
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now