miércoles, 22 de julio de 2020

2/2 Conjunto de Acceso archivo DB vb.net - sql server (no olvidar diseñar el archivo XML)


Imports System.Data.SqlClient
Public Class AccesoArchivos

#Region "Declaraciones"

    Private Connection As New SqlConnection
    Private Connection2 As New SqlConnection
    Private DB As New AccesoXML

#End Region

#Region "Propiedades"

    Public Property Conn() As SqlConnection
        Get
            Return Connection
        End Get
        Set(ByVal value As SqlConnection)
            Connection = value
        End Set
    End Property

    Public Property Conn2() As SqlConnection
        Get
            Return Connection2
        End Get
        Set(ByVal value As SqlConnection)
            Connection2 = value
        End Set
    End Property

#End Region

#Region "Constructores"

    Public Sub New()
        MyBase.New()
        Constructor()

    End Sub

    Private Sub Constructor()
        Connection.ConnectionString = DB.ConexionString

    End Sub


#End Region

End Class

Public Class AccesoXML

#Region "Declaraciones"

    Private Server As String
    Private Base As String
    Private Path As String
    Private Conn As String
    Private Conn2 As String
    'Private ObjRemisionRN As GestionStockRN

#End Region

#Region "Constructores"

    Public Sub New()
        MyBase.New()
        Constructor()

    End Sub

    Private Sub Constructor()
        LeerXML()
    End Sub


#End Region

#Region "Propiedades"

    Public Property Servidor() As String
        Get
            Return Server
        End Get
        Set(ByVal value As String)
            Server = value
        End Set
    End Property

    Public Property ConexionString() As String
        Get
            Return Conn
        End Get
        Set(ByVal value As String)
            Conn = value
        End Set
    End Property

    Public Property BaseDatos() As String
        Get
            Return Base
        End Get
        Set(ByVal value As String)
            Base = value
        End Set
    End Property

    Public Property Servidor2() As String
        Get
            Return Server
        End Get
        Set(ByVal value As String)
            Server = value
        End Set
    End Property

    Public Property ConexionString2() As String
        Get
            Return Conn
        End Get
        Set(ByVal value As String)
            Conn = value
        End Set
    End Property

    Public Property BaseDatos2() As String
        Get
            Return Base
        End Get
        Set(ByVal value As String)
            Base = value
        End Set
    End Property

#End Region

#Region "Metodos"

    Public Sub LeerXML()
        Try
            Dim ConfigXML As Xml.XmlReader
            ConfigXML = New Xml.XmlTextReader(My.Application.Info.DirectoryPath & "\config.xml")

            ' ConfigXML.WhitespaceHandling = WhitespaceHandling.None

            ConfigXML.Read()

            ConfigXML.Read()

            While Not ConfigXML.EOF
                ConfigXML.Read()

                If ConfigXML.GetAttribute("Valor") = "DB" Then
                    ConfigXML.Read()
                    Servidor = ConfigXML.ReadElementString("Servidor")
                    BaseDatos = ConfigXML.ReadElementString("Base")
                End If
            End While
            
            ConexionString = "Server=" & Servidor & ";Database=" & BaseDatos & ";User Id=admin;Integrated Security=true" 

            ConfigXML.Close()
        Catch ex As Exception
            'MENSAJE DE ERROR

        End Try

    End Sub

#End Region




End Class

No hay comentarios:

Publicar un comentario

Los mail de oulook no se pueden reenviar.

 cuando en el asunto poseen un caracter especial por ejemplo @#$ los correos no salen y no te muestra ningun correo de rebote, especialmente...