Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Programtically changing the location of a database
Message
General information
Forum:
Visual FoxPro
Category:
Crystal Reports
Miscellaneous
Thread ID:
00702755
Message ID:
00707224
Views:
16
I use a DNS on a DBC which changes. ex C: \Amline\Data1 or C: \Amline\Data2
I do not have any problem!

Firstly Make a DNS by programming
#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




To connect the data.
*---------------------------------------------------------------------------------------------------
*-- 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
.DATABASE.TABLES.ITEM( 1 ).SetLogOnInfo(cNewODBC, "", "", "")
.DATABASE.TABLES.ITEM( 1 ).Location = cNewTableName
lSuccess = .T.
EXIT FOR
ENDIF
ENDFOR

ENDWITH

RETURN lSuccess
ENDPROC
Previous
Reply
Map
View

Click here to load this message in the networking platform