Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.IO
Imports System.Reflection
Public Class ActualizaConfig
Public Sub New()
MyBase.New()
'El Diseñador de componentes requiere esta llamada.
InitializeComponent()
'Agregue el código de inicialización después de llamar a InitializeComponent
End Sub
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
Dim directorio As String = Me.Context.Parameters.Item("directorio")
Dim servidor As String = Me.Context.Parameters.Item("server")
Dim execpath As String = String.Format("{0}AplicaOlivar2010.exe", directorio)
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(execpath)
''
Dim frm As New ElegirServidor()
frm.ShowDialog()
servidor = frm.ComboBox1.SelectedItem
config.ConnectionStrings.ConnectionStrings("Almazara2010Conexion").ConnectionString = "Data source=" _
& servidor & "; Initial Catalog=master; Integrated Security=True"
config.Save()
crearBaseDatos(config)
End Sub
Public Sub crearBaseDatos(ByVal config As Configuration)
Dim conexion As New SqlConnection(config.ConnectionStrings.ConnectionStrings("Almazara2010Conexion").ConnectionString)
Dim cmd As New SqlCommand("Create Database Almazara2010", conexion)
conexion.Open()
cmd.ExecuteNonQuery()
conexion.Close()
config.ConnectionStrings.ConnectionStrings("Almazara2010Conexion").ConnectionString = config.ConnectionStrings.ConnectionStrings("Almazara2010Conexion").ConnectionString.Replace("master", "Almazara2010")
config.Save()
conexion.ConnectionString = config.ConnectionStrings.ConnectionStrings("Almazara2010Conexion").ConnectionString
'Para cambiar la conectionstring segunda
config.ConnectionStrings.ConnectionStrings("WindowsApplication2.My.MySettings.Almazara2010ConnectionString").ConnectionString = config.ConnectionStrings.ConnectionStrings("Almazara2010Conexion").ConnectionString.Replace("master", "Almazara2010")
config.Save()
conexion.ConnectionString = config.ConnectionStrings.ConnectionStrings("WindowsApplication2.My.MySettings.Almazara2010ConnectionString").ConnectionString
'Crear las tablas
conexion.ConnectionString = config.ConnectionStrings.ConnectionStrings("WindowsApplication2.My.MySettings.Almazara2010ConnectionString").ConnectionString
Dim Command As New SqlClient.SqlCommand(GetSql("tablas.txt"), conexion)
Command.Connection.Open()
Command.ExecuteNonQuery()
Command.Connection.Close()
End Sub
Private Function GetSql(ByVal Name As String) As String
Try
' Gets the current assembly.
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()
' Resources are named using a fully qualified name.
Dim strm As Stream = Asm.GetManifestResourceStream( _
Asm.GetName().Name + "." + Name)
' Reads the contents of the embedded file.
Dim reader As StreamReader = New StreamReader(strm)
Return reader.ReadToEnd()
Catch ex As Exception
MsgBox("In GetSQL: " & ex.Message)
Throw ex
End Try
End Function