Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/05/2011, 17:03
mactus
 
Fecha de Ingreso: noviembre-2007
Mensajes: 81
Antigüedad: 16 años, 5 meses
Puntos: 0
Información Coneccion sql server por ip en VB

Hola necesito de su ayuda anteriormente realice un programa el cual se conectaba a SQL Server Manager Studio localmente y todo salio bien ahora mi base esta en un servidor remoto en SQL Server 2003 yo me conecto a el por escritorio remoto con un usuario y contraseña

Yo use este codigo pero he leido que hay que sustituir por servidor por la ip mas mi usser y pass mi pregunta el usuario que uso para conectarme por el escritorio remoto es el que debo usar para la coneccion? en este uso Administrador Corporativo pero no me pide contraseña ni nada Ayuda!!!

Código:
Imports System.Data.SqlClient 'LIBRERIA PARA MANEJAR OBJETOS Y CLASE DE SQL SERVER

Public Class Form1

    Private Const cs As String = "Server=.\SQLEXPRESS;Database=mibase;Trusted_Connection=True;" 

    Public a As Integer

    Dim conexion As New SqlConnection 'DECLARAS TU CONEXION
    Dim comando As New SqlCommand 'DECLARAS TU COMANDO
    Dim lectura As SqlDataReader 'DECLARAMOS LO QUE VA SER NUESTRA LECTURA DE DATOS

 Private Sub btnbuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbuscar.Click
        conexion.ConnectionString = "Server=.\SQLEXPRESS;Database=MiBase;Trusted_Connection=True;" 'TU CONEXION
        Dim subcom As Integer
        Dim number1 As Integer = 1

        btncancelar.Visible = True
        subcom = cmbpoa.Text.Substring(0, 5)

        '--------------------


        Try
            conexion.Open() 'ABRE TU CONEXION 
            comando.Connection = conexion 'INDICAS QUE EL COMANDO ES PARTE DE LA CONEXION
            comando.CommandText = "Select * from mespre  "
            lectura = comando.ExecuteReader

            If lectura.Read() Then
                camp1.Text = lectura.Item("Campo1").ToString() 'DEPOSITAMOS 
                camp2.Text = lectura.Item("Campo2").ToString() 'DEPOSITAMOS 

                
                lectura.Close() 'CERRAMOS LA LECTURA
            End If
            'SENTENCIA lectura.Read()

        Catch excepcion As SqlException ' DECLARAS EXCEPCION 
            conexion.Close() 'CIERRA TU CONEXION
        Finally
            If conexion.State = ConnectionState.Open Then
                conexion.Close()
            End If
        End Try 'CIERRAS TRY


    End Sub
En que estoy mal?

Gracias por su ayuda