Solved

Run DDL SQL Commands With Delphi

Posted on 2006-11-03
11
411 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 98
indy Tmemory stream non latin charcter issue 2 110
Press three keys together and trigger a function 3 55
RESTRequest Parameter 4 30
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

17 Experts available now in Live!

Get 1:1 Help Now