Vous êtes sur la page 1sur 3

' Elaborado por: Yelitza Suniaga (SQL Script) y Alexander Osorio (Vb Script)

' Fecha: 30/Nov/2006


' Notas:
' Latebinding IN VBScript
Dim oServer ' SQLDMO.SQLServer
Dim oDb ' SQLDMO.database
Dim server ' SQLDMO.SQLServer
Dim database ' SQLDMO.database
Dim backup ' SQLDMO.backup
Dim Restore ' SQLDMO.Restore
Dim NewDb ' As String
Dim OldDb ' As String
Dim m_Codigo
Dim m_DbName
Dim m_DbPath
Const RestoreActionType_Database = 0
Const RestoreActionType_Log = 4
Const DeviceType_File = 2
Const SQLDMOExec_ContinueOnError = 2
Sub Main()
msgbox AppObj.EmpresaSeleccionda.Codigo
' " " & mDbName & " " & mDbPath
Exit Sub

' msgbox "NewDbMSSQL. Rutinas para la creación de una Base de Datos de Empresa
en Formato Microsoft SQL Server"
' msgbox mCodEmp & " " & mDbName & " " & mDbPath
' Hacerlas Públicas para todas las Subrutinas, ya que estan declaradas al inici
ar el script
m_Codigo = mCodEmp : m_DbName = mDbName : m_DbPath = mDbPath
Call ImportarEmpresa
msgbox "Proceso Culminado"
Exit Sub
' oDir = App.Path
' If Right(oDir, 1) <> "\" then
' oDir = oDir & "\"
' End if
' oDir = oDir & "Strdbf\"
' srcFile = oDir & "StrMdb.mdb"
' dstFile = mDbPath & mdbName
'' msgbox srcFile & " " & dstFile
' FileCopy srcFile , dstFile
' Exit Sub
End Sub
Sub ImportarEmpresa
If App.dbConexionConfig = "" then msgbox "No hay conexion declarada" : Exit
Sub
If InStr(1,UCase(App.dbConexionConfig), "JET") > 0 Then Exit Sub ' El BackEn
d es MsJet Access
oIniFile = App.Path & "\" & "Sayger.Ini"
oSqlScript = App.Path & "\" & "Buildemp.sql"
' MSGBOX oSqlScript
oServerName = GetProfile("LAN", "SERVER", oIniFile)
If oServerName = "" Then oServerName = "(Local)"
' oDest = GetProfile("DATABASE", "DBDIR", oIniFile)
oDest = GetProfile("DATABASE", "SQLDBDIR", oIniFile)
' Fisical Name:
' c:\publica\database\Emp005\Actual.mdf"
' c:\publica\database\Emp005\Emp005_Actual.ldf"
' Logical Name:
' EMP005_Actual
' EMP005_Actual_log
oName_dat = "EMP" & m_Codigo & "_ACTUAL"
oName_log = "EMP" & m_Codigo & "_ACTUAL_LOG"
oDest_Dat = oDest & "\" & "EMP" & m_Codigo & "\Actual.mdf" ' c:\publica\da
tabase\Emp005\Actual.mdf"
oDest_Log = oDest & "\" & "EMP" & m_Codigo & "\" & "Emp" & m_Codigo & "_Ac
tual.ldf" ' c:\publica\database\Emp005\Emp005_Actual.ldf"
' msgbox "Datos en : " & oDest_Dat & vbCr & "Logs en : " & oDest_Log & vbCr
& "Nombre Datos: " & oName_dat & vbCr & "Nombre Logs: " & oName_log
' Exit Sub
Dim SQLScript
Dim oLine
Dim sSQL
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SQLScript = FSO.OpenTextFile(oSqlScript)
sSQL = ""
oLine = ""
dim nTimes
nTimes = 0
do until SQLScript.atendofstream = True
oLine = SQLScript.readline
oLine = strtran(oLine,"{pNAMEMDF}",oName_Dat)
oLine = strtran(oLine,"{pNAMELDF}",oName_log)
oLine = strtran(oLine,"{pFILEMDF}",oDest_Dat)
oLine = strtran(oLine,"{pFILELDF}",oDest_Log)
' if nTimes < 1000 then
sSQL = sSQL & vbCr & oLine
' nTimes = nTimes + 1
' end if
loop
' msgbox sSQL
' Exit Sub
'On Error resume Next
Set oServer= CreateObject("SQLDMO.Sqlserver")
Set oDb = CreateObject("SQLDMO.database")
oServer.LoginSecure=True
' oServer.Connect (ServerName)
oServer.Connect (oServerName)
set oDatabases=oServer.Databases
swExisteConfig = 0
for each oDb in oDatabases
if uCase(oDb.Name) = uCase(oName_dat) then
swExisteConfig = 1
end if
next
If swExisteConfig = 0 Then
' Crearla
' Form.LblMensaje.Caption = "Creando de la Base de Datos, esto puede tarda
r..."
oServer.ExecuteImmediate sSQL, SQLDMOExec_ContinueOnError
' Form.LblMensaje.Caption = ""
msgbox "La Base de Datos ha sido Creada"
End if
oServer.Disconnect
set oDb = Nothing
set oDatabases = Nothing
set oServer=Nothing
Set SQLScript = Nothing
Set FSO = Nothing
'On error resume Next
If swExisteConfig = 0 Then
' Set WshShell = CreateObject("WScript.Shell")
' sFillDatabase = App.Path & "\" & "Iniciar Datos de Tablas en Config.Exe"
' nReturn = WshShell.Run(chr(34) & sFillDatabase & chr(34), 1, True)
' WriteProfile "CONFIGDB", "VERSION", "1.02", oIniFile ' A Nivel General
de toda la APP, hay un solo config
' Set WshShell = Nothing
End If
Exit Sub
End Sub

Vous aimerez peut-être aussi