none
Ayuda urgente conexion sql 2005 con vb 6.0 RRS feed

  • Pregunta

  • alguien podria explicarme como conectar con una base de datos sql 2005 cn vb 6.0 y extraer los datos? porque asi no me funciona y lo e provado de 2 manera 1:

     

    Private Sub btnConectar_Click()
        ' La conexión a la base de datos
        Dim cn As adodb.Connection
        Set cn = New adodb.Connection
       
        cnn.ConnectionString = "{SQL Server};Server=Liven1;Database=SSI.mdb;Uid=myUsername;Pwd=myPassword"
       
        ' El recordset para acceder a los datos
        Dim rs As adodb.Recordset
        Set rs = New adodb.Recordset

       

        ' Abrir el recordset de forma estática, no vamos a cambiar datos
       
        rs.Close
        cn.Close
    End Sub

     

     

    manera 2:

     

     

    Private Sub btnConectar_Click()
        ' La conexión a la base de datos
        Dim cn As adodb.Connection
        Set cn = New adodb.Connection
       
        ' Para la cadena de selección
        Dim sSelect As String
       
        ' Para usar un fichero directamente:
        Dim sBase As String

        ' Poner aquí el path y el nombre de la base
        sBase = "E:\sql\SSI_Data.MDF"
        ' Y la cadena de selección adecuada
        sSelect = "SELECT  TOP (100) PERCENT dbo.PDVCA.Fecha, dbo.PDVLI.Linea, dbo.PDVLI.Almacen, dbo.PDVLI.Articulo, dbo.PDVCA.[Document], dbo.PDGLE.LinSigno, "
                   
                   
                          GPAI1_2.Nombre AS EnProvincia, GPAI0_2.Nombre AS Pais, dbo.PDVCA.CPostal, dbo.PDVCA.Tlfno1, dbo.PDVCA.Tlfno2, dbo.PDVCA.Fax,
                          dbo.CMONE.Descript, dbo.PDVCA.Clave, dbo.PDVCA.Transpor, dbo.PDVCA.Portes, dbo.PDVCA.SuRef, dbo.PDVCA.Tarifa, dbo.PDVCA.Vendedor,
                          dbo.PDVCA.FchPagCo, dbo.PDVCA.Bultos, dbo.PDVCA.Envio, dbo.PDVCA.EnNom, dbo.PDVCA.EnSiglas, dbo.PDVCA.EnDomici,
                          CONVERT(VARCHAR(4000), dbo.PDVCA.EnAmplia) AS EnAmplia, dbo.PDVCA.EnNumero, dbo.PDVCA.EnLocali, dbo.PDVLI.Descripc, dbo.PDVLI.PVenta,
                          dbo.PDVLI.CantEco, dbo.PDVLI.Impuesto, dbo.PDVLI.UniLote, dbo.PDVLI.DescLote, dbo.PDVLI.Tributar, dbo.PDVLI.Recargo, dbo.PDVLI.Largo,
                          dbo.PDVLI.Ancho, dbo.PDVLI.Alto, dbo.PDGLE.Bruto, dbo.PDGLE.NetoLin, dbo.PDGLE.DtoFinan, dbo.PDGLE.CargoFin, dbo.PDGLE.Irpf,
                          dbo.PDGLE.Impuesto AS LineIva, dbo.PDGLE.TotLin, dbo.PDGLE.PesoNeto, dbo.PDGCE.Neto, dbo.PDGCE.CuotaImp, dbo.PDGCE.CuotaRec,
                          dbo.PDGCE.Impuesto AS CabIva, dbo.PDGCE.Aduana, dbo.PDGCE.Arancel, dbo.PDGCE.Portes AS CabPortes, dbo.PDGCE.Gastos, dbo.PDGCE.Total,
                          dbo.PDGCE.Bruto AS CabBruto, dbo.PDGCE.Volumen, dbo.PARTI.Clave AS Familia, dbo.PARTI.Proveedo, dbo.PARTI.UM_Manip, dbo.PDVCA.Nif,
                          dbo.FTERC.Codigo, dbo.PDVCA.Cuenta, dbo.PDVCA.RefNum, dbo.PDVCA.RefSerie, dbo.PDVCA.Signo, dbo.PDVCA.TipoDoc, dbo.PDVCA.Ejercic,
                          dbo.PDVCA.Serie, dbo.PDVCA.Razon, dbo.PDVCA.Referenc, dbo.SFPCA.Descripc AS FormaPago, CONVERT(VARCHAR(4000), dbo.PARTT.Ampliaci)
                          AS ApliArti, dbo.GrupoLivenCuentasBancarias.Entidad, dbo.GrupoLivenCuentasBancarias.Domicili AS DomBanco,
                          dbo.GrupoLivenCuentasBancarias.Localid, dbo.GrupoLivenCuentasBancarias.CodBanco, dbo.GrupoLivenCuentasBancarias.CodAgenc,
                          dbo.GrupoLivenCuentasBancarias.DigCtrol, dbo.GrupoLivenCuentasBancarias.NumCta, dbo.PDVCA.EnComuni, dbo.PDVCA.EnPais,
                          dbo.PDVCA.EnTerrit, dbo.PDVCA.EnCPosta, dbo.PDVCA.EnTel1, dbo.PDVCA.EnTel2, dbo.PDVCA.EnFax, dbo.PDVCA.EnContac, dbo.PDVCA.EnPOp,
                          dbo.PARTI.Peso, dbo.PUMAN.Descripc AS Unimalupu, dbo.PUMAN.Factor, dbo.PDVCA.Cambio, dbo.PDVLI.CantMan, dbo.PDVLI.CantPEco,
                          dbo.PDVLI.CantPMan, dbo.PDIRE.Ficha AS DENVFICHA, dbo.PDIRE.Nombre AS DENVNOMBRE, dbo.PDIRE.Contacto AS DENVCONTACTO,
                          dbo.PDIRE.Domicili AS DENVDOMICIL, dbo.PDIRE.Localida AS DENVLOCALID, dbo.PDIRE.Provinci AS DENVPROVINC,
                          dbo.PVEND.Nombre AS VENDNOMBRE, dbo.PARTI.UM_Econo, dbo.PDGLE.DtosArti, dbo.PDGLE.CargArti, dbo.PDGLE.Bonifi, dbo.PDGLE.NetoArt,
                          dbo.PDGLE.DtosCome, dbo.PDGLE.PorteRep, dbo.PDGLE.GastoRep, dbo.PDGLE.PesoBPro, dbo.PDGLE.VolmLin, dbo.PDVLI.DtoCar01,
                          dbo.PDVLI.DtoCar02, dbo.PDVCA.Limite, dbo.PDVCA.POperac, dbo.PDVCA.RefExt, dbo.PDVLI.UMManip, dbo.SEMPE.Nombre AS EMPRESA,
                          dbo.PDVLI.Prevista, CONVERT(VARCHAR(4000), dbo.PDVLI.Observac) AS Lobservac, CONVERT(VARCHAR(4000), dbo.PDVCA.Observac) AS Cobservac,
                          GPAI0_1.Nombre AS EnPaisNom, GPAI1_1.Nombre AS EnProvNom, dbo.GrupoLivenDocumentoAnteriorCSA.Descripc AS DescripcOrigen,
                          dbo.GrupoLivenDocumentoAnteriorCSA.SerieOrigen, dbo.GrupoLivenDocumentoAnteriorCSA.DocumentOrigen,
                          dbo.GrupoLivenDocumentoAnteriorCSA.FechaOrigen, dbo.GrupoLivenDocumentoAnteriorCSA.SuRefOrigen,
                          dbo.GrupoLivenDocumentoAnteriorCSA.FechaLimiteOrigen, dbo.PMOPT.CantEco AS CantMov, dbo.PMOPT.Partida, dbo.PMOPT.CantMan AS CMovUM,
                          dbo.PPART.Fec_Cadu AS FechaCad, dbo.PTRAN.Nombre AS NomTransport, GPAI1_2.Nombre AS Provincia, dbo.PDVCA.DtoFin,
                          dbo.PDGCE.ImDtFin AS CabImDtFin, dbo.PDVDC.Porcen1 AS PorcenDtoCom, dbo.PDGCE.DtosCom AS CabDtosCom, dbo.PFA_SIS2NPR.C0001,
                          dbo.PARTI.Clasif, dbo.PDGCE.NetoArt AS TNetoArt, dbo.A_CSA_Descrip_Extranjero.Referencia,
                          dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas.C0006 AS PaletCajasPorPalet, dbo.PARTI.CodBarra, PFA_SIS2ART_1.C0002,
                          dbo.PPART.Partida AS Expr1, dbo.A_CSA_Descrip_Extranjero.DescripExtranjero,
                          dbo.PDVLI.CantMan / dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas.C0006 AS NumPalet,
                          ROUND(dbo.PDVLI.CantMan / dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas.C0006, 0, 1) AS NumPaletRound,
                          (dbo.PDVLI.CantMan / dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas.C0006 - ROUND(dbo.PDVLI.CantMan / dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas.C0006,
                           0, 1)) * dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas.C0006 AS PicosPalet, dbo.PFA_LIVEN4CAM.C0001 AS CambioCZK
    FROM         dbo.PUMAN RIGHT OUTER JOIN
                          dbo.PDGLE RIGHT OUTER JOIN
                          dbo.PARTI LEFT OUTER JOIN
                          dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas ON
                          dbo.PARTI.Codigo = dbo.GrupoLivenNumeroDeCajasPorPaletSinEmpresaParaTodas.Articulo RIGHT OUTER JOIN
                          dbo.GPAI1 AS GPAI1_2 RIGHT OUTER JOIN
                          dbo.GPAI0 AS GPAI0_1 RIGHT OUTER JOIN
                          dbo.GPAI1 AS GPAI1_1 RIGHT OUTER JOIN
                          dbo.PTRAN RIGHT OUTER JOIN
                          dbo.PDVDC RIGHT OUTER JOIN
                          dbo.GrupoLivenCuentasBancarias RIGHT OUTER JOIN
                          dbo.PFA_SIS2NPR RIGHT OUTER JOIN
                          dbo.PFA_SIS2ART AS PFA_SIS2ART_2 INNER JOIN
                          dbo.PFA_SIS2ART AS PFA_SIS2ART_1 ON PFA_SIS2ART_2.ROW_ID = PFA_SIS2ART_1.ROW_ID AND
                          PFA_SIS2ART_2.Indice = PFA_SIS2ART_1.Indice AND PFA_SIS2ART_2.Cuenta = PFA_SIS2ART_1.Cuenta AND
                          PFA_SIS2ART_2.GRP_ID = PFA_SIS2ART_1.GRP_ID AND PFA_SIS2ART_2.C0001 = PFA_SIS2ART_1.C0001 RIGHT OUTER JOIN
                          dbo.PDVCA LEFT OUTER JOIN
                          dbo.PFA_LIVEN4CAM ON dbo.PDVCA.Signo = dbo.PFA_LIVEN4CAM.Signo AND dbo.PDVCA.RefSerie = dbo.PFA_LIVEN4CAM.RefSerie AND
                          dbo.PDVCA.RefNum = dbo.PFA_LIVEN4CAM.RefNum LEFT OUTER JOIN
                          dbo.PMOPT LEFT OUTER JOIN
                          dbo.PPART ON dbo.PMOPT.Partida = dbo.PPART.Partida AND dbo.PMOPT.GRP_ID = dbo.PPART.GRP_ID RIGHT OUTER JOIN
                          dbo.PDVLI LEFT OUTER JOIN
                          dbo.GrupoLivenDocumentoAnteriorCSA ON dbo.PDVLI.GRP_ID = dbo.GrupoLivenDocumentoAnteriorCSA.GRP_ID AND
                          dbo.PDVLI.LinSigno = dbo.GrupoLivenDocumentoAnteriorCSA.LinDeSig AND dbo.PDVLI.LinSerie = dbo.GrupoLivenDocumentoAnteriorCSA.LinDeSer AND
                           dbo.PDVLI.RefLNum = dbo.GrupoLivenDocumentoAnteriorCSA.LinDeNum ON
                          dbo.PMOPT.GRP_ID = dbo.GrupoLivenDocumentoAnteriorCSA.GRP_ID AND dbo.PMOPT.LinSig = dbo.GrupoLivenDocumentoAnteriorCSA.LOrigSig AND
                          dbo.PMOPT.LinSerie = dbo.GrupoLivenDocumentoAnteriorCSA.LinOrSer AND
                          dbo.PMOPT.RefLNum = dbo.GrupoLivenDocumentoAnteriorCSA.LinOrNum AND dbo.PPART.GRP_ID = dbo.PDVLI.GRP_ID AND
                          dbo.PPART.Almacen = dbo.PDVLI.Almacen AND dbo.PPART.Articulo = dbo.PDVLI.Articulo ON dbo.PDVCA.GRP_ID = dbo.PDVLI.GRP_ID AND
                          dbo.PDVCA.Signo = dbo.PDVLI.Signo AND dbo.PDVCA.RefSerie = dbo.PDVLI.RefSerie AND dbo.PDVCA.RefNum = dbo.PDVLI.RefNum ON
                          PFA_SIS2ART_2.GRP_ID = dbo.PDVLI.GRP_ID AND PFA_SIS2ART_2.C0001 = dbo.PDVLI.Articulo AND
                          PFA_SIS2ART_1.GRP_ID = dbo.PDVCA.GRP_ID AND PFA_SIS2ART_1.Cuenta = dbo.PDVCA.Cuenta ON
                          dbo.PFA_SIS2NPR.Cuenta = dbo.PDVCA.Cuenta AND dbo.PFA_SIS2NPR.GRP_ID = dbo.PDVCA.GRP_ID ON
                          dbo.GrupoLivenCuentasBancarias.Codigo = dbo.PDVCA.Cuenta AND dbo.GrupoLivenCuentasBancarias.GRP_ID = dbo.PDVCA.GRP_ID ON
                          dbo.PDVDC.RefNum = dbo.PDVCA.RefNum AND dbo.PDVDC.RefSerie = dbo.PDVCA.RefSerie AND dbo.PDVDC.Signo = dbo.PDVCA.Signo AND
                          dbo.PDVDC.GRP_ID = dbo.PDVCA.GRP_ID ON dbo.PTRAN.Codigo = dbo.PDVCA.Transpor AND dbo.PTRAN.GRP_ID = dbo.PDVCA.GRP_ID ON
                          GPAI1_1.CodPais = dbo.PDVCA.EnPais AND GPAI1_1.CodProvi = dbo.PDVCA.EnTerrit ON GPAI0_1.CodPais = dbo.PDVCA.EnPais LEFT OUTER JOIN
                          dbo.SFPCA ON dbo.PDVCA.Pago = dbo.SFPCA.Codigo AND dbo.PDVCA.GRP_ID = dbo.SFPCA.GRP_ID LEFT OUTER JOIN
                          dbo.PVEND ON dbo.PDVCA.GRP_ID = dbo.PVEND.GRP_ID AND dbo.PDVCA.Vendedor = dbo.PVEND.Codigo LEFT OUTER JOIN
                          dbo.SEMPE ON dbo.PDVCA.GRP_ID = dbo.SEMPE.GRP_ID LEFT OUTER JOIN
                          dbo.GPAI0 AS GPAI0_2 ON dbo.PDVCA.Pais = GPAI0_2.CodPais LEFT OUTER JOIN
                          dbo.FTERC ON dbo.PDVCA.GRP_ID = dbo.FTERC.GRP_ID AND dbo.PDVCA.Nif = dbo.FTERC.IdFiscal LEFT OUTER JOIN
                          dbo.CMONE ON dbo.PDVCA.GRP_ID = dbo.CMONE.GRP_ID AND dbo.PDVCA.Moneda = dbo.CMONE.Codigo LEFT OUTER JOIN
                          dbo.PDGCE ON dbo.PDVCA.GRP_ID = dbo.PDGCE.GRP_ID AND dbo.PDVCA.RefNum = dbo.PDGCE.RefNum AND
                          dbo.PDVCA.RefSerie = dbo.PDGCE.RefSerie AND dbo.PDVCA.Signo = dbo.PDGCE.Signo LEFT OUTER JOIN
                          dbo.PDIRE ON dbo.PDVCA.GRP_ID = dbo.PDIRE.GRP_ID AND dbo.PDVCA.Cuenta = dbo.PDIRE.Cliente AND dbo.PDVCA.Envio = dbo.PDIRE.Ficha ON
                          GPAI1_2.CodPais = dbo.PDVCA.Pais AND GPAI1_2.CodProvi = dbo.PDVCA.Territor LEFT OUTER JOIN
                          dbo.A_CSA_Descrip_Extranjero ON dbo.PDVLI.GRP_ID = dbo.A_CSA_Descrip_Extranjero.GRP_ID AND
                          dbo.PDVLI.LinSigno = dbo.A_CSA_Descrip_Extranjero.LinSigno AND dbo.PDVLI.LinSerie = dbo.A_CSA_Descrip_Extranjero.LinSerie AND
                          dbo.PDVLI.RefLNum = dbo.A_CSA_Descrip_Extranjero.RefLNum ON dbo.PARTI.GRP_ID = dbo.PDVLI.GRP_ID AND
                          dbo.PARTI.Codigo = dbo.PDVLI.Articulo ON dbo.PDGLE.GRP_ID = dbo.PDVLI.GRP_ID AND dbo.PDGLE.RefLNum = dbo.PDVLI.RefLNum AND
                          dbo.PDGLE.LinSerie = dbo.PDVLI.LinSerie AND dbo.PDGLE.LinSigno = dbo.PDVLI.LinSigno ON dbo.PUMAN.Codigo = dbo.PARTI.UM_Manip AND
                          dbo.PUMAN.GRP_ID = dbo.PARTI.GRP_ID LEFT OUTER JOIN
                          dbo.PARTT ON dbo.PARTI.GRP_ID = dbo.PARTT.GRP_ID AND dbo.PARTI.Codigo = dbo.PARTT.Codigo
    ORDER BY dbo.PDVLI.Linea"
        '
        cnn.ConnectionString = "{SQL Server};Server=Liven1;Database=SSI.mdb;Uid=myUsername;Pwd=myPassword"
       
        ' El recordset para acceder a los datos
        Dim rs As adodb.Recordset
        Set rs = New adodb.Recordset

        ' Abrir el recordset de forma estática, no vamos a cambiar datos
        rs.Open sSelect, cn, adOpenStatic
        rs.Close
        cn.Close
    End Sub

    martes, 30 de octubre de 2007 10:34

Respuestas

  • Me parece que el problema lo tenes en el string de conexion, yo he probado con vb6 y sql express

    y no tuve problemas te paso un string de conexion para que lo veas

    "Provider=SQLOLEDB.1;Password=mypwd;Persist Security Info=True;User ID=sa;Initial Catalog=mybase;Data Source=PCDESARROLLO\SQLEXPRESS"

     

    No se si es exactamente igual con las otras versiones de sql 2005 supongo que si

     

    esto es para el primer metodo que es el mismo que uso yo

     

    Espero que te sirva

    jueves, 1 de noviembre de 2007 17:15

Todas las respuestas