Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Code Problem
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01564364
Message ID:
01565711
Vues:
60
>Ok, thanks for this. The problem now is that I think the connection string is wrong. I'm getting
>
>"Error 1526. Cannot make connection.
>Connectivity error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
>


Your connection string is not right. You use OLEDB provider string, not ODBC one.
Try:
...
** Here I use SQL Server driver. This is a driver that comes with Windows.
** but it is for SQL Server 2000. You could use some of the "Native Client" drivers that comes with SQL Server. 
sqlProcs.ConnectionString = "Driver={SQL Server};Server=192.168.2.5;DataBase=Spares2;UID=Kevin;PWD=password1"
...
>
>It's been a LONG time since I did any VFP. What's wrong here?
>
>
>
>>>Bear in mind that I haven't touched VFP in 10+ years....
>>>
>>>I'm writing this:
>>>
>>>
>>>CLEAR
>>>sqlProcs = CREATEOBJECT("MyStuff ")
>>>sqlProcs.ConnectionString = "Data Source=192.168.2.5;Initial Catalog=Spares2;User Id=Kevin;Password=password1"
>>>
>>>LOCAL conneted as Boolean
>>>conneted = sqlProcs.TestConnection()
>>>
>>>IF sqlProcs.ErrorOccured
>>>	? sqlProcs.ErrorMessage
>>>ELSE
>>>	? conneted
>>>ENDIF
>>>
>>>
>>>
>>>#DEFINE TRUE	.T.
>>>#DEFINE FALSE	.F.
>>>#DEFINE NEWLINE CHR(13)
>>>
>>>DEFINE CLASS MyStuff AS Custom
>>>
>>>	connectionHandle = 0;
>>>
>>>	ErrorMessasge = ""
>>>	ErrorOccured = FALSE
>>>	
>>>	ConnectionString = ""
>>>	PROCEDURE ConnectionString_Access()
>>>    	RETURN This.ConnectionString 
>>>	ENDPROC
>>>
>>>	PROCEDURE ConnectionString_Assign(PropValue)
>>>    	This.ConnectionString   = PropValue
>>>	ENDPROC
>>>
>>>	**********************************************************
>>>	* Function.: TestConnection
>>>	* Purpose..: Tests a connnection to SQL Server
>>>	*
>>>	**********************************************************
>>>  	FUNCTION TestConnection() AS Boolean
>>>
>>>		LOCAL Connected AS Boolean
>>>		Connected = TRUE
>>>
>>>		IF This.ConnectionString = "" THEN
>>>			ErrorMessasge = "No connection string specified"
>>>			ErrorOccured = TRUE
>>>		ENDIF
>>>		
>>>		IF NOT ErrorOccured 
>>>			SQLSETPROP(0,"DispLogin",3)
>>>
>>>			TRY
>>>				connectionHandle = SQLSTRINGCONNECT(This.ConnectionString)
>>>			CATCH TO exceptionObject
>>>				AERROR(errorArray)
>>>		   		ErrorMessasge = "Error " + ALLTRIwM(STR(errorArray(0))) + ". Cannot make connection." + NEWLINE + errorArray(1)
>>>		   		ErrorOccured = TRUE
>>>				Connected = FALSE
>>>			ENDTRY
>>>				   
>>>			IF connectionHandle >0
>>>			   = SQLDISCONNECT(connectionHandle )
>>>			ENDIF
>>>			
>>>		ENDIF
>>>		
>>>	RETURN Connected
>>>
>>>
>>>ENDDEFINE
>>>
>>>
>>>When I run this, the connection string property is empty down in TestConnection
>>>
>>>What am I doing wrong here???
>>
>>Modified version of your code:
>>
>>CLEAR
>>sqlProcs = CREATEOBJECT("MyStuff")
>>sqlProcs.ConnectionString = "Data Source=192.168.2.5;Initial Catalog=Spares2;User Id=Kevin;Password=password1"
>>
>>LOCAL conneted as Boolean
>>CLEAR
>>
>>conneted = sqlProcs.TestConnection()
>>
>>IF sqlProcs.ErrorOccured
>>    ? sqlProcs.ErrorMessage, sqlProcs.ConnectionString
>>ELSE
>>    ? conneted, sqlProcs.connectionHandle 
>>    
>>ENDIF
>>
>>
>>
>>#DEFINE TRUE    .T.
>>#DEFINE FALSE    .F.
>>#DEFINE NEWLINE CHR(13)
>>
>>DEFINE CLASS MyStuff AS Custom
>>
>>    connectionHandle = 0;
>>
>>    ErrorMessage = ""
>>    ErrorOccured = FALSE
>>    
>>    ConnectionString = ""
>>    PROCEDURE ConnectionString_Access()
>>        RETURN This.ConnectionString 
>>    ENDPROC
>>
>>    PROCEDURE ConnectionString_Assign(PropValue)
>>        This.ConnectionString   = PropValue
>>    ENDPROC
>>
>>    **********************************************************
>>    * Function.: TestConnection
>>    * Purpose..: Tests a connnection to SQL Server
>>    *
>>    **********************************************************
>>      FUNCTION TestConnection() AS Boolean
>>
>>        LOCAL Connected AS Boolean
>>        
>>
>>        IF This.ConnectionString == "" THEN
>>            this.ErrorMessage = "No connection string specified"
>>            this.ErrorOccured = TRUE
>>        ENDIF
>>        
>>        IF NOT this.ErrorOccured
>>            SQLSETPROP(0,"DispLogin",3)
>>            this.connectionHandle = SQLSTRINGCONNECT(This.ConnectionString)
>>            IF this.connectionHandle < 0
>>                AERROR(errorArray)
>>                this.ErrorMessage = "Error " + ALLTRIM(STR(errorArray[1])) +;
>>                                    ". Cannot make connection." + NEWLINE + errorArray(2)
>>                this.ErrorOccured = TRUE
>>            ELSE
>>                Connected = TRUE
>>            ENDIF
>>                   
>>            IF this.connectionHandle >0
>>               = SQLDISCONNECT(connectionHandle )
>>            ENDIF
>>            
>>        ENDIF
>>        
>>    RETURN Connected
>>
>>
>>ENDDEFINE
>>
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform