create database SQL Server

create database SQL Server

Postby lucasdebeltran » 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.
Last edited by lucasdebeltran on Fri Aug 16, 2013 2:09 pm, edited 1 time in total.
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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: create table SQL Server

Postby Rick Lipkin » Fri Aug 16, 2013 1:26 pm

Lucas

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

Rick Lipkin
Code: Select all  Expand view

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()

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: create table SQL Server

Postby lucasdebeltran » Fri Aug 16, 2013 2: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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: create database SQL Server

Postby nageswaragunupudi » Fri Aug 16, 2013 2:32 pm

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: create database SQL Server

Postby lucasdebeltran » Fri Aug 16, 2013 3: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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: create database SQL Server

Postby nageswaragunupudi » Fri Aug 16, 2013 9: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
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 40 guests