Solved

Run DDL SQL Commands With Delphi

Posted on 2006-11-03
11
425 Views
Last Modified: 2010-04-05
hello
i am working with delphi2005 and SQL server 2000
i want run sql commands (CREATE DATABASE,CREATE TABLE and attach,backup,restore ...) with delphi in run time.
please help me step by step with a example
thanks a lot
0
Comment
Question by:mr_mpz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17869471
depending on your database and your privileges
you can place the ddl-statment in a query and use the execSQL-method

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17869480
>delphi2005 and SQL server 2000
never used one of them

meikl ;-)
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17872569
Use AdoCommand from Ado Components
or the SqlQuery from dbExpress
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:mr_mpz
ID: 17877446
dear frined
i am not a beginer in delphi,i am working with delphi from ver 2 until ver2005.
but i don't need work with sql server,i work with sql server 2000 now and i want backup from database in runtime in delphi or attach or disattach and more.
i test it woth ADO too,but all my request not work correct
with query this command not work correct,please help me with correct sample
thanks
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17880211
No one said in comments that you are beginner ;-)

anyway, as me and meikl told you, any query component will work, also I prefer to use AdoCommand with ado for DLL statement, for example to create database just do

   cmd1.CommandText := 'create database SqlDB';
   cmd1.Execute;

and you can do any other DLL as the same way,

BTW, the adoCommand above attached to connection which connect to sql server without specifing a database

HTH
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17880238
guess a typo

DLL -> DDL

meikl ;-)
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17880303
Thanks Meikl :-)
0
 
LVL 1

Author Comment

by:mr_mpz
ID: 17881094
dear friends
thanks from you
i test this way (adocommand) for create database but this way doesn't work for other command.
please say to me a example for Attach database and deattach
thanks a lot
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17888013
Hi,

It's also easy :-)

here's two buttons, one will deattach the database and the other to reattach it again

procedure TForm8.btnDeattachDBClick(Sender: TObject);
begin
  cmd1.CommandText :='sp_detach_db "pubs"';
  cmd1.Execute;
end;

procedure TForm8.btnAttachDBClick(Sender: TObject);
begin
  cmd1.CommandText :='sp_attach_single_file_db @dbname = "pubs", ' +
          ' @physname = "C:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf"';
  cmd1.Execute;
end;

Regards,
Mohammed
0
 
LVL 1

Author Comment

by:mr_mpz
ID: 17899981
dear mohammed
thanks from your answer,this work correct
in adocommand ,what is  connectionstring?
i want connect to sql server without ODBC
thanks
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 150 total points
ID: 17920627
for windows integerated security
Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=pubs;

if you use sql server security

Provider=SQLOLEDB.1;user id=sa;password=password;Initial Catalog=pubs;
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month4 days, 6 hours left to enroll

630 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