I have to create a database in MS-Sql server automatically from my install program.
Is it possible, using ADO, to issue direct native "sql-string" calls to a sql-server to create the following?
- users
- databases
-schemas?
#INCLUDE "FIVEWIN.CH"
#INCLUDE "xbrowse.CH"
//----------------------
Function main()
LOCAL oRs1,oRs2,oRs3,oErr,cSQl1,cSql2, cSQL,cTitle,oBrw,oWnd
msgInfo("Start")
cSQL := "create database jbc"
cSql1:= "CREATE LOGIN jbc2 WITH PASSWORD = 'hhhh'; ";
+"USE jbc; ";
+"CREATE USER jbc2 FOR LOGIN jbc2 "
cSQl2 := "CREATE SCHEMA jbc AUTHORIZATION jbc2 ";
+"CREATE TABLE test (source int, cost int, partnumber int) ";
+"GRANT SELECT TO jbc2 "
oRs1 := TOleAuto():New( "ADODB.Recordset" )
oRs1:CursorType := 1 // opendkeyset
oRs1:CursorLocation := 3 // local cache
oRs1:LockType := 3 // lockoportunistic
TRY
oRS1:Open( cSql,'Provider=SQLOLEDB;Data Source=OGNEW;Initial Catalog=;User Id=sa1;Password=qqqe' )
CATCH oErr
MsgInfo( "Error in creating database" )
RETURN(.F.)
END TRY
oRs3 := TOleAuto():New( "ADODB.Recordset" )
oRs3:CursorType := 1 // opendkeyset
oRs3:CursorLocation := 3 // local cache
oRs3:LockType := 3 // lockoportunistic
TRY
oRs3:Open( cSql1,'Provider=SQLOLEDB;Data Source=OGNEW;Initial Catalog=;User Id=sa1;Password=qqqe' )
CATCH oErr
MsgInfo( "Error in creating user" )
RETURN(.F.)
END TRY
oRs2 := TOleAuto():New( "ADODB.Recordset" )
oRs2:CursorType := 1 // opendkeyset
oRs2:CursorLocation := 3 // local cache
oRs2:LockType := 3 // lockoportunistic
TRY
oRs2:Open( cSql2,'Provider=SQLOLEDB;Data Source=OGNEW;Initial Catalog=jbc;User Id=sa1;Password=qqqe' )
CATCH oErr
MsgInfo( "Error in crating table" )
RETURN(.F.)
END TRY
Return nil
#INCLUDE "FIVEWIN.CH"
//----------------------
Function main()
LOCAL oRs1,oErr,cSQL
msgInfo("Start")
cSQL:="RESTORE DATABASE jbc ";
+"FROM DISK = 'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\jbc.bak' "
oRs1 := TOleAuto():New( "ADODB.Recordset" )
oRs1:CursorType := 1 // opendkeyset
oRs1:CursorLocation := 3 // local cache
oRs1:LockType := 3 // lockoportunistic
TRY
oRS1:Open( cSql,'Provider=SQLOLEDB;Data Source=OGNEW;Initial Catalog=;User Id=sa1;Password='qqqe' )
CATCH oErr
MsgInfo( "Error in restoring database" )
END TRY
Return nil
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 45 guests