Return to Snippet

Revision: 70402
at February 5, 2016 03:28 by systemergon


Initial Code
Imports System
Imports System.IO
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient

Public Class DBSQLServer

#Region "Properties"
    Private con As New SqlConnection
    Private cmd As New SqlCommand
    Private reader As SqlDataReader
    Private da As SqlDataAdapter

    Public Property StringConnection As String = ""
    Public Property Host() As String
    Public Property DBName() As String
    Public Property User() As String
    Public Property Pass() As String
    Public Property Port() As String = 3306

#End Region

#Region "Constructores"
    Public Sub New(ByVal host As String, ByVal user As String, ByVal pass As String, ByVal DBName As String, ByVal Port As String)
        Me.Host = host
        Me.User = user
        Me.Pass = pass
        Me.DBName = DBName
        Me.Port = Port
    End Sub

    Public Sub New(ByVal host As String, ByVal user As String, ByVal pass As String, ByVal DBName As String)
        Me.Host = host
        Me.User = user
        Me.Pass = pass
        Me.DBName = DBName
    End Sub

    Public Sub New(ByVal strConnection As String)
        Me.StringConnection = strConnection
    End Sub

#End Region

#Region "Functions"
    ''' <summary>
    ''' conexion a la base de datos segun los parametros de  constructor.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function conecctedDB() As SqlConnection
        Try
            If (Me.StringConnection.Trim().Length > 0) Then
                Me.con = New SqlConnection(Me.StringConnection)
            Else
                Me.con = New SqlConnection(String.Format("Data Source={0}; Integrated Security=False; Id={1}; Password={2}; Catalog={3};", Me.Host, Me.User, Me.Pass, Me.DBName))
            End If
            Me.con.Open()
        Catch ex As SqlException
            Throw New System.Exception("Error de conexion a la basde de datos: (conectarBase)", ex)

        End Try

        Return Me.con

    End Function


#End Region

End Class

Initial URL

                                

Initial Description
Conexión a base de datos con los parametros que llega del contructor

Initial Title
Funcion conectar a BD SQL Server (sqlconection)

Initial Tags
sql, server

Initial Language
VB.NET