Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run DDL SQL Commands With Delphi

Posted on 2006-11-03
11
Medium Priority
?
435 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 450 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

704 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