Crear Conexion Individual vb.net y sqlserver

Imports System.Data.SqlClient
Public Class Conexionfrm
    
    Private Sub Conexion_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim con As String = "Server=" & TextBox1.Text & ";Database=" & TextBox2.Text & ";User ID=" & TextBox3.Text & ";Password=" & TextBox4.Text
        Dim conexion As New SqlConnection(con)
        TextBox5.Text = con
        Try
            If conexion.State = ConnectionState.Closed Then
                conexion.Open()
                Label6.Text = "Conexion Activa Exitosa."
                Label6.ForeColor = Color.Green
                Button2.Enabled = True
            End If
        Catch ex As Exception
            Label6.ForeColor = Color.Red
            Label6.Text = "Error conectandose a la base de datos Verificar."
        End Try


    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            Dim obj As Object
            Dim archivo As Object
            Try
                obj = CreateObject("Scripting.FileSystemObject")
            Catch ex As Exception
                MsgBox("Error Creando Conexion2.")
            End Try
            archivo = obj.CreateTextFile("\Cone.txt")
            archivo.writeline(TextBox5.Text)
            archivo.close()
            Me.Hide()
        Catch ex As Exception
            MsgBox("Error Creando Conexion.")
        End Try

    End Sub
End Class
Compartir En Redes Sociales

Deja un comentario