elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Conexion a base de datos
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Conexion a base de datos  (Leído 2,853 veces)
leliCabello

Desconectado Desconectado

Mensajes: 158


Ver Perfil
Conexion a base de datos
« en: 1 Mayo 2010, 21:10 pm »

qtal amigos, ps quiero que me ayuden en esto de conexion con base de datos sql2005, este es mi codigo, pero no logro conectar, ya que deberia boterme un mensaje si lo haria. Ayudenme pleaseeeeeee :-(
Código:
Public cn As ADODB.Connection
_____________________________________________________________

Public Sub Main()
Dim Y As String
Dim X As String
Dim n As String
Dim AdoErr As ADODB.Error
banderatipocambio = False
banderatipocambio2 = False
Set cn = New ADODB.Connection
On Error GoTo TrataError
Y = "servidorticom"
X = "ticom"
n = "sa"
With cn
    .Provider = "SQLOLEDB"
    Beep
    For Each AdoErr In cn.Errors
        MsgBox AdoErr.Description
    Next
    .ConnectionString = "Data Source=" & Y & ";" & _
                            "Initial Catalog=" & X & ";" & _
                            "User Id=" & n & ";" & _
                            "Password="
        .Open
End With
MsgBox "Conexión Conforme a " & Y
TrataError:
mdiPrincipal.Show
'frmNum2Let.Show
End Sub


En línea

e500

Desconectado Desconectado

Mensajes: 83


Ver Perfil
Re: Conexion a base de datos
« Respuesta #1 en: 2 Mayo 2010, 05:37 am »

Tienes instalado el SQL Server 2005?
Tienes Creada la Base de Datos SQL?

Saludos


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Conexion a base de datos
« Respuesta #2 en: 2 Mayo 2010, 07:53 am »

Te diré una cosa a mi no me gusta para nada estar invocando a cada rato en cada botón y en cada acción la conexión tal cual la realizas en el sub main()

Actualmente ya no trato con vb6 (me pase a .NET por que me lo exigieron y como no es mucha la diferencia...).

Este es un Modulo de Clase tal cual manejo en mis conexiones (Sirve para modo Multi-Hilos que es como lo trabajo)

Código
  1.  
  2. '
  3. '   /////////////////////////////////////////////////////////////
  4. '   // Autor:   BlackZeroX ( Ortega Avila Miguel Angel )       //
  5. '   //                                                         //
  6. '   // Web:     http://InfrAngeluX.Sytes.Net/                  //
  7. '   //                                                         //
  8. '   //    |-> Pueden Distribuir Este Codigo siempre y cuando   //
  9. '   // no se eliminen los creditos originales de este codigo   //
  10. '   // No importando que sea modificado/editado o engrandesido //
  11. '   // o achicado, si es en base a este codigo es requerido    //
  12. '   // el agradacimiento al autor.                             //
  13. '   /////////////////////////////////////////////////////////////
  14.  
  15. Option Explicit On
  16.  
  17. Imports MySql.Data.MySqlClient
  18.  
  19. Public Class Cls_Ado
  20.  
  21.    '   //  Constantes de conexión a MySQL por ADO .NET!¡.
  22.    Private Const PreStrConexion As String = "Server=(ip);Database=(db);user id=(u);password=(p);Connect Timeout=30;"
  23.    Private Const PREDBIpServer As String = "127.0.0.1"                  '   //  Predeterminado Default
  24.    Private Const PREDBUser As String = "root"                           '   //  Predeterminado Default
  25.    Private Const PREDBPass As String = "root"                           '   //  Predeterminado Default
  26.    Private Const PREDBIni As String = "Integra"                         '   //  Predeterminado
  27.  
  28.    '   //  Otros.
  29.    Private StrConexion As String
  30.    Private MySQLConnectionString As String
  31.  
  32.    '   //  .||.
  33.    Private MyDataAdapter As MySqlDataAdapter
  34.    Private MyCommandBuilder As MySqlCommandBuilder
  35.  
  36.    '   //  .||.
  37.    Private DBIpServer As String
  38.    Private DBUser As String
  39.    Private DBPass As String
  40.    Private DBIni As String
  41.  
  42.    Private PrivDataSet As DataSet
  43.    Private PrivSqlQuery As String
  44.    Private PrivTable As String
  45.    Private PrivThisTheardTag As String
  46.  
  47.    Event ErrorEvent(ByVal Ex As Exception, ByVal Cancel As Boolean)
  48.    Event Finish()
  49.  
  50.    Public Property StringConection() As String
  51.        Get
  52.            Return StrConexion
  53.        End Get
  54.        Set(ByVal value As String)
  55.            StrConexion = value
  56.        End Set
  57.    End Property
  58.  
  59.    Public Property This_Theard_Tag() As String
  60.        Get
  61.            Return PrivThisTheardTag
  62.        End Get
  63.        Set(ByVal value As String)
  64.            PrivThisTheardTag = value
  65.        End Set
  66.    End Property
  67.  
  68.    Public Property ServerIP() As String
  69.        Get
  70.            Return DBIpServer
  71.        End Get
  72.        Set(ByVal value As String)
  73.            DBIpServer = value
  74.        End Set
  75.    End Property
  76.  
  77.    Public Property ServerDataBase() As String
  78.        Get
  79.            Return DBIni
  80.        End Get
  81.        Set(ByVal value As String)
  82.            DBIni = value
  83.        End Set
  84.    End Property
  85.  
  86.    Public Property ServerPassword() As String
  87.        Get
  88.            Return DBPass
  89.        End Get
  90.        Set(ByVal value As String)
  91.            DBPass = value
  92.        End Set
  93.    End Property
  94.  
  95.    Public Property ServerUserName() As String
  96.        Get
  97.            Return DBUser
  98.        End Get
  99.        Set(ByVal value As String)
  100.            DBUser = value
  101.        End Set
  102.    End Property
  103.  
  104.    Public Function OpenDBMySql(ByVal pServidorIPDNS As String, ByVal pDBuser As String, ByVal pDBPass As String, _
  105.                                 ByVal pBDD As String, ByVal SqlQuery As String, ByVal MySQLConnectionString As String) _
  106.    As MySql.Data.MySqlClient.MySqlConnection
  107.  
  108.        Dim MyADOConnection As MySql.Data.MySqlClient.MySqlConnection
  109.  
  110.        If StrConexion = Nothing And MySQLConnectionString = Nothing Then
  111.            MySQLConnectionString = PreStrConexion
  112.        Else
  113.            If MySQLConnectionString = Nothing Then
  114.                MySQLConnectionString = StrConexion
  115.            End If
  116.        End If
  117.        If pServidorIPDNS = Nothing And DBIpServer = Nothing Then
  118.            pServidorIPDNS = PREDBIpServer
  119.        Else
  120.            If pServidorIPDNS = Nothing Then
  121.                pServidorIPDNS = DBIpServer
  122.            End If
  123.        End If
  124.        If pDBuser = Nothing And DBUser = Nothing Then
  125.            pDBuser = PREDBUser
  126.        Else
  127.            If pDBuser = Nothing Then
  128.                pDBuser = DBUser
  129.            End If
  130.        End If
  131.        If pDBPass = Nothing And DBPass = Nothing Then
  132.            pDBPass = PREDBPass
  133.        Else
  134.            If pDBPass = Nothing Then
  135.                pDBPass = DBPass
  136.            End If
  137.        End If
  138.        If pBDD = Nothing And DBIni = Nothing Then
  139.            pBDD = PREDBIni
  140.        Else
  141.            If pBDD = Nothing Then
  142.                pBDD = DBIni
  143.            End If
  144.        End If
  145.  
  146.        MySQLConnectionString = MySQLConnectionString.Replace("(ip)", pServidorIPDNS). _
  147.                                Replace("(db)", pBDD).Replace("(u)", pDBuser).Replace("(p)", pDBPass)
  148.  
  149.        If Not MyDataAdapter Is Nothing Then
  150.            MyDataAdapter = Nothing
  151.        End If
  152.        If Not MyCommandBuilder Is Nothing Then
  153.            MyCommandBuilder = Nothing
  154.        End If
  155.  
  156.        Try
  157.            MyADOConnection = New MySql.Data.MySqlClient.MySqlConnection(MySQLConnectionString)
  158.            MyDataAdapter = New MySqlDataAdapter(SqlQuery, MyADOConnection)
  159.            MyCommandBuilder = New MySqlCommandBuilder(MyDataAdapter)
  160.            Return MyADOConnection
  161.        Catch ex As Exception
  162.            Dim Cancel As Boolean
  163.            RaiseEvent ErrorEvent(ex, Cancel)
  164.            Return Nothing
  165.        End Try
  166.  
  167.    End Function
  168.  
  169.    Public Function ExecuteQuery(ByVal SqlQuery As String, ByVal Tabla As String) As Boolean
  170.        Dim MyComandoMysql As New MySqlCommand
  171.        Dim MyADOConnection As MySql.Data.MySqlClient.MySqlConnection
  172.        If Not SqlQuery = "" Then
  173.            PrivSqlQuery = SqlQuery
  174.        End If
  175.        If Tabla = "" Then
  176.            PrivTable = Tabla
  177.        End If
  178.        MyADOConnection = OpenDBMySql(DBIpServer, DBUser, DBPass, DBIni, PrivSqlQuery, StrConexion)
  179.        If Not MyADOConnection Is Nothing Then
  180.            Try
  181.                MyADOConnection.Open()
  182.                MyComandoMysql.Connection = MyADOConnection
  183.                MyComandoMysql.CommandType = CommandType.Text
  184.                MyComandoMysql.CommandText = SqlQuery
  185.                MyComandoMysql.ExecuteNonQuery()
  186.                MyADOConnection.Close()
  187.                RaiseEvent Finish()
  188.                Return True
  189.            Catch ex As Exception
  190.                Dim Cancel As Boolean
  191.                RaiseEvent ErrorEvent(ex, Cancel)
  192.                Return False
  193.            End Try
  194.        Else
  195.            RaiseEvent Finish()
  196.            Return False
  197.        End If
  198.    End Function
  199.  
  200.    Public Function GetDataSet(Optional ByVal SqlQuery As String = "", Optional ByVal Tabla As String = "") As DataSet
  201.        Dim tmpDataSet As New DataSet
  202.        Dim MyComandoMysql As New MySqlCommand
  203.        Dim MyADOConnection As MySql.Data.MySqlClient.MySqlConnection
  204.        If Not SqlQuery = "" Then
  205.            PrivSqlQuery = SqlQuery
  206.        End If
  207.        If Not Tabla = "" Then
  208.            PrivTable = Tabla
  209.        End If
  210.        MyADOConnection = OpenDBMySql(DBIpServer, DBUser, DBPass, DBIni, PrivSqlQuery, StrConexion)
  211.        If Not MyADOConnection Is Nothing Then
  212.            Try
  213.                MyADOConnection.Open()
  214.                MyComandoMysql.Connection = MyADOConnection
  215.                MyComandoMysql.CommandType = CommandType.Text
  216.                MyComandoMysql.CommandText = PrivSqlQuery
  217.                MyComandoMysql.ExecuteNonQuery()
  218.                MyDataAdapter.Fill(tmpDataSet, PrivTable)
  219.                MyADOConnection.Close()
  220.            Catch ex As Exception
  221.                Dim Cancel As Boolean
  222.                RaiseEvent ErrorEvent(ex, Cancel)
  223.                If Cancel Then
  224.                    RaiseEvent Finish()
  225.                    Return Nothing
  226.                End If
  227.                tmpDataSet = Nothing
  228.            End Try
  229.            PrivDataSet = tmpDataSet
  230.            RaiseEvent Finish()
  231.            Return tmpDataSet
  232.        Else
  233.            RaiseEvent Finish()
  234.            Return Nothing
  235.        End If
  236.    End Function
  237.  
  238.    Public Property This_DataBase() As DataSet
  239.        Get
  240.            Return PrivDataSet
  241.        End Get
  242.        Set(ByVal value As DataSet)
  243.            PrivDataSet = value
  244.        End Set
  245.    End Property
  246.  
  247.    Public Property This_SqlQuery() As String
  248.        Get
  249.            Return PrivSqlQuery
  250.        End Get
  251.        Set(ByVal value As String)
  252.            PrivSqlQuery = value
  253.        End Set
  254.    End Property
  255.  
  256.    Public Property This_Table() As String
  257.        Get
  258.            Return PrivTable
  259.        End Get
  260.        Set(ByVal value As String)
  261.            PrivTable = value
  262.        End Set
  263.    End Property
  264.  
  265.    Public Function UpdateFromDataSet(Optional ByVal pDataSet As DataSet = Nothing, _
  266.                                      Optional ByVal SQLQuery As String = "", _
  267.                                      Optional ByVal Tabla As String = "") _
  268.    As Boolean
  269.  
  270.        If Not pDataSet Is Nothing Then
  271.            PrivDataSet = pDataSet
  272.        End If
  273.        If Not SQLQuery = "" Then
  274.            PrivSqlQuery = SQLQuery
  275.        End If
  276.        If Not Tabla = "" Then
  277.            PrivTable = Tabla
  278.        End If
  279.  
  280.        Dim MyADOConnection As MySql.Data.MySqlClient.MySqlConnection
  281.        MyADOConnection = OpenDBMySql(DBIpServer, DBUser, DBPass, DBIni, PrivSqlQuery, StrConexion)
  282.        If Not MyADOConnection Is Nothing Then
  283.            Try
  284.                MyADOConnection.Open()
  285.                MyDataAdapter.Update(PrivDataSet, PrivTable)
  286.                MyADOConnection.Close()
  287.                RaiseEvent Finish()
  288.                Return True
  289.            Catch ex As Exception
  290.                Dim Cancel As Boolean
  291.                RaiseEvent ErrorEvent(ex, Cancel)
  292.                RaiseEvent Finish()
  293.                Return False
  294.            End Try
  295.        Else
  296.            RaiseEvent Finish()
  297.            Return False
  298.        End If
  299.    End Function
  300.  
  301. End Class
  302.  
  303.  


PD.: Se que esta no es la sección de .Net ya. pero e visto muchos códigos de esta manera de hecho donde laboro los programadores hace los mimo (Con alter-ego y código desorganizado (Todo en los formularios y botones... pero bueno)) y bueno viendo que .NET no es mucha la diferencia te puse algo mas o menos igual... solo son equivalencias todo es lo mismo por ejemplo DataSet seri en vb6 el DaraRecord/RecordSet o algo asi era xP...!¡.

Sangriento Infierno Lunar!¡.
« Última modificación: 2 Mayo 2010, 08:03 am por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
leliCabello

Desconectado Desconectado

Mensajes: 158


Ver Perfil
Re: Conexion a base de datos
« Respuesta #3 en: 3 Mayo 2010, 15:48 pm »

si e500 tengo todo instalado lo q no entiendo es xq no se conecta :-(<<-----------ayudamee----------------->>
En línea

Angeldj27

Desconectado Desconectado

Mensajes: 199


Ahorra Agua... Beba Cerveza


Ver Perfil
Re: Conexion a base de datos
« Respuesta #4 en: 3 Mayo 2010, 20:46 pm »

Lo que veo es que no le estas pasando la password..

Intenta con este otro codigo

Código
  1. 'para abrir
  2. Public Sub Open_cn()
  3. On Error GoTo errhandler
  4.    Set cmd = New ADODB.Command
  5.    Set cn = New ADODB.Connection
  6.  
  7.    With cn
  8.        .Provider = "MSDASQL;DRIVER={SQL Server};SERVER=" & strServer & ";trusted_connection=no;user id= " & strUID & ";password=" & strPWD & " ;database=" & strDatabase & ";"
  9.        .Open
  10.  
  11.    End With
  12.    cnOpen = True
  13.  
  14.  
  15. Exit Sub
  16. errhandler:
  17. Call MsgBox("Error.", vbOKOnly, "Error")
  18.  
  19. strServer = ""
  20.  
  21.  
  22. cnOpen = False
  23.  
  24. End Sub
  25.  
  26. 'Para cerrar
  27. Public Sub Close_cn()
  28.     If cnOpen = True Then
  29.  
  30.         cn.Close
  31.         Set cn = Nothing        
  32.         cnOpen = False
  33.    End If
  34.  
  35. End Sub
En línea



"Que vamos a hacer Mañana?..... Lo mismo que hacemos todos los dias Pinky tratar de Conquistar el Mundoooo!!!!!
43H4FH44H45H4CH49H56H45H
Wiki

Desconectado Desconectado

Mensajes: 502



Ver Perfil
Re: Conexion a base de datos
« Respuesta #5 en: 3 Mayo 2010, 20:53 pm »

si e500 tengo todo instalado lo q no entiendo es xq no se conecta :-(<<-----------ayudamee----------------->>

Podria ser que Sql Server 2005 no esta en:

Código:
Mixed Mode (Windows Authentication and SQL Server Authentication)

en ese caso trata de conectar con una "Autenticación de Windows", prueba con este enlace para saber si hiciste todo bien con las referencias.

http://www.elguille.info/vb/bases/ADO/SQLServer2005_Visual_Basic_6.htm

Además instala el Microsoft SQL Server Management Studio Express y prueba desde ahí, para saber si tu usuario y contraseña pueden conectarse sin problemas.
En línea


-R IP
:0100
-A 100 
2826:0100 MOV AH,09
2826:0102 MOV DX,109
2826:0105 INT 21
2826:0105 MOV AH,08
2826:0105 INT 21
2826:0107 INT 20
2826:0109 DB 'MI NICK ES CODELIVE.$' 
2826:0127 
-R BX
:0000
-R CX
:20
-N CODELIVE.COM
-W
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda con conexión a base de datos!
PHP
kodeone 3 2,163 Último mensaje 24 Febrero 2011, 17:38 pm
por kodeone
controlador para conexión base de datos db2
Java
KuraraGNU 0 4,380 Último mensaje 8 Marzo 2011, 12:16 pm
por KuraraGNU
conexion a una base de datos creada en postgresql
Bases de Datos
EFRAINPACHECO 1 2,176 Último mensaje 13 Junio 2011, 20:06 pm
por Shell Root
proteger cadena de conexion a base de datos VS2008
Seguridad
xuturk 2 5,460 Último mensaje 20 Septiembre 2011, 16:21 pm
por n0more
Ayuda con conexión de base de datos !Urgente!
.NET (C#, VB.NET, ASP)
Brian1511 9 5,646 Último mensaje 28 Octubre 2012, 06:34 am
por .::IT::.
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines