Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cannot connect ADO data source to reports
Message
De
31/08/2002 10:22:28
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Crystal Reports
Divers
Thread ID:
00695306
Message ID:
00695652
Vues:
12
If you use a DSN, you are using ODBC. If you use the DSN for an ADO connection, you will use the OLE DB Provider for ODBC to connect to the DSN. The code I posted does not use ODBC, but connects directly to the OLE DB Provider.


>Hello craig,
>
>I made as a preliminary a connection ADO.
>
>Currently
>
>1) MAKE a DNS at the entry of the program.
>*------------------------------------------------------
>#DEFINE ODBC_ADD_DSN 1 &&' Add data source
>#DEFINE ODBC_CONFIG_DSN 2 &&' Configure (edit) data source
>#DEFINE ODBC_REMOVE_DSN 3 &&' Remove data source
>#DEFINE vbAPINull 0 &&' NULL Pointer
>
>*'Function Declare
>* #If WIN32 Then
>DECLARE LONG SQLConfigDataSource IN ODBCCP32.DLL ;
> LONG hwndParent, LONG fRequest, ;
> STRING lpszDriver, STRING lpszAttributes
>*#Else
>* Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
>* (ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
>* lpszDriver As String, ByVal lpszAttributes As String) As Integer
>*#End If
>
>LOCAL intRet, strDriver, strAttributes
>
>*'Set the driver to SQL Server because it is most common.
>strDriver = "Microsoft Visual FoxPro Driver" && "SQL Server"
>*'Set the attributes delimited by null.
>*'See driver documentation for a complete
>*'list of supported attributes.
>*strAttributes = "SERVER=SomeServer" + CHR(0)
>
>strAttributes = "DESCRIPTION=Temp DSN" + CHR(0)
>strAttributes = strAttributes + "DSN=Amline3.0" + CHR(0)
>strAttributes = strAttributes + "SourceType=DBC" + CHR(0)
>strAttributes = strAttributes + "SourceDB =" + goapp.cdefaultdirectory + "AMLINE.DBC" + CHR(0)
>*strAttributes = strAttributes + "UID=sa" + CHR(0)
>*strAttributes = strAttributes + "PWD=" + CHR(0)
>*'To show dialog, use Form1.Hwnd instead of vbAPINull.
>intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, ;
> strDriver, strAttributes)
>
>IF intRet>0
> * =MESSAGEBOX( "DSN Created" )
>ELSE
> =MESSAGEBOX( "La Connection DNS a échoué !" )
>ENDIF
>
>
>
>
>2)Connect my vieuw ( in the DBC ) (ReportForm)
> *-- Exemple .aCursors[ 1 ] = "Lv_customer" (View in the DBC)
> oCrystal.changedataSource( "Amline3.0", UPPER( ALLTRIM( .aCursors[ 1 ] ) ) )
>*-------------------------------------------------------------------------------------
>
>
> *---------------------------------------------------------------------------------------------------
> *-- Change the data source of a report at runtime.
> PROCEDURE changedataSource
> *------------------------------------------------------------------------------------------------
> LPARAMETERS cNewODBC, cTableName, cNewTableName
>
> *
> * cNewODBC ODBC DSN to use for this run
> * cTableName Name of the table this is to be applied to
> * cNewTableName New name of table if appropriate
> *
> LOCAL nItems, lSuccess
> lSuccess = .F.
> IF VARTYPE(cNewODBC) # 'C' OR VARTYPE(cTableName) # 'C'
> RETURN lSuccess
> ENDIF
> IF EMPTY(cNewTableName)
> cNewTableName = cTableName
> ENDIF
>
>
> *
> * Ensure '.dsn' is not included - also remember the ODBC name is CaSe SeNsItIvE
> *
> cNewODBC = STRTRAN( cNewODBC, '.dsn', '')
>
> WITH THIS.crreport
> nItems = .DATABASE.TABLES.COUNT
>
> FOR nX = 1 TO nItems
> *
> IF UPPER( ALLTRIM( .DATABASE.TABLES.ITEM( nX ).Location ) ) = cTableName
> * WAIT WINDOW "Connection Serveur Ok " TIMEOUT 4
> .DATABASE.TABLES.ITEM( 1 ).SetLogOnInfo(cNewODBC, "", "", "")
> .DATABASE.TABLES.ITEM( 1 ).Location = cNewTableName
> lSuccess = .T.
> EXIT FOR
> ENDIF
> ENDFOR
>
> ENDWITH
>
> RETURN lSuccess
> ENDPROC
>*--------------------------------------------------------------------------------------
>
>
>I calculated time between the two ways of proceeding and I noticed that the second was faster .
>What are you thinking abaout That ?
>
>Bernhart
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform