FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour create database SQL Server
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
create database SQL Server
Posted: Fri Aug 16, 2013 10:28 AM

Hello,

After installing SQL Express server, I need to create the main database, without the Management Studio Express.

Is it posible?.

Thank you so much.

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: create table SQL Server
Posted: Fri Aug 16, 2013 01:26 PM
Lucas

Here is a snipit from one of my install programs ..

Rick Lipkin
Code (fw): Select all Collapse
Try
     oCn  := CREATEOBJECT( "ADODB.Connection" )
  Catch
     Saying := "Could not create an ADO COnnection"
     MsgInfo( Saying )
     oDLG:End()
     Return(.f.)
   End Try

   // assumes database has been created 
   // and you want to add tables

   TRY
     oCn:Open( xCONNECT )
    CATCH oErr
      Saying := "Sorry .. It does not appear the database "+xCatalog+chr(10)
      Saying += "Exists on Sql Server "+xSource+chr(10)
      Saying += "Please contact your Sql Server DBA"+chr(10)
      MsgInfo( Saying )
      oDLG:End()
      RETURN(.F.)
   END TRY

   oCn:Close()
   oCn := nil

   oRs := TOleAuto():New( "ADODB.Recordset" )
   oRs:CursorType     := 1        // opendkeyset
   oRs:CursorLocation := 3        // local cache
   oRs:LockType       := 3        // lockoportunistic

   // check for very first table

   cSQL := "SELECT * FROM USERINFO"
   TRY
      oRs:Open( cSQL, xCONNECT )
   CATCH oErr
      Saying := "WARNING .. the Database File "+xSource+chr(10)
      Saying += "appears to exist, however the Tables have not been created"+chr(10)
      Saying += "If this is your First time using this Program ..."+chr(10)
      Saying += "Please proceed, otherwise contact your Administrator"+chr(10)
      Saying += " "+chr(10)
      Saying += "Do you wish to proceed to create the NEW Database  Tables ?"+chr(10)

      If MsgNoYes( saying )
         lCreate := .t.
      Else
         oDlg:End()
         Return(.f.)
      Endif
   End Try

   oRs:CLose()
   oRs := nil

   lCreate := .f.

End Case

If lCreate = .t.

   // create tables
   Try
     oCn  := CREATEOBJECT( "ADODB.Connection" )
   Catch
     MsgInfo( "Could not create the ADO object for connection")
     oDLG:End()
     Return(.f.)
  End Try

   TRY
     oCn:Open( xCONNECT )
   CATCH oErr
      MsgInfo( "Could not open a Connection to Database "+xSource )
      oDLG:End()
      RETURN(.F.)
   END TRY

   cSQL := "CREATE TABLE UserInfo"
   cSQL += "( "
   cSQL += "[USEREID]   char(18) NOT NULL, "
   cSQL += "[USERID]    char(25) NULL, "
   cSQL += "[LNAME]     char(15) NULL, "
   cSQL += "[FNAME]     char(1)  NULL, "
   cSQL += "[READONLY]  char(1) NULL, "
   cSQL += "[WRITEONLY] char(1) NULL, "
   cSQL += "[SUPER]     char(1) NULL, "
   cSQL += "[ADMIN]     char(1) NULL, "
   cSQL += "[ENTRYBY]   char(25) NULL, "
   cSQL += "[ENTRYDATE] DATETIME NULL, "
   cSQL += "[LASTLOG]   DATETIME NULL, "
   cSQL += "[PASSWORD]  char(16) NULL, "
   cSQL += "[UPDATED] SMALLINT DEFAULT 0, "
   cSQL += "CONSTRAINT PK_USERINFO PRIMARY KEY ( USEREID )"
   cSQL += " )"

   // create the table Userinfo
   // with primary key

   Try
      oCn:Execute( cSQL )
   Catch
      MsgInfo( "Create Table USERINFO Failed" )
      oDLG:End()
      Return(.f.)
   End try

   cSay := "Created Table Userinfo"
   oSay:ReFresh()
   SysReFresh()

   oCn:Close()
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: create table SQL Server
Posted: Fri Aug 16, 2013 02:08 PM

Thank you, but my mistake, I need to create the database, not the tables.

Sorry.

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: create database SQL Server
Posted: Fri Aug 16, 2013 02:32 PM

Connect without initial catalog
Execute the sql statement "CREATE DATABASE MYDATA", with oCn:Execute( cSql )

Regards



G. N. Rao.

Hyderabad, India
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: create database SQL Server
Posted: Fri Aug 16, 2013 03:32 PM

Thank You ver y much.

Andrés is It posible to add a user to the Sql server?.

Thank you

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: create database SQL Server
Posted: Fri Aug 16, 2013 09:14 PM

oCn:Execute( "CREATE USER <name> WITH PASSWORD = '<password>'" )

http://technet.microsoft.com/en-us/libr ... 73463.aspx

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion