/ Published in: VB.NET
Conexión a base de datos con los parametros que llega del contructor
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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 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