Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ignore parameters with SQLExec?
Message
From
05/05/2011 17:53:38
Joel Leach
Memorial Business Systems, Inc.
Tennessee, United States
 
 
To
05/05/2011 13:46:20
Joel Leach
Memorial Business Systems, Inc.
Tennessee, United States
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
MS SQL Server
Miscellaneous
Thread ID:
01509693
Message ID:
01509751
Views:
163
This message has been marked as the solution to the initial question of the thread.
>I am working on a script to create a database in SQL Server 2008. The script includes the creation of UDFs, and at least one of those contains a "?" in the UDF. Since SQLDMO is apparently gone, I am working on using SQLExec() to execute the script. The problem is that SQLExec() is interpreting the "?" as a parameter (and prompting for a value) when it is not. Is there anyway to tell SQLExec() to ignore anything it interprets as a parameter?
>

Apparently, there is no way around this using SQLExec(): http://stackoverflow.com/questions/3348932/how-to-avoid-odbc-parameterization-for-the-question-mark-character-within-liter

However, the same problem does not occur if you use ADO to send the commands. Another well known issue is that you can not send commands containing GO to SQL Server. Although GO works in SSMS, it is not officially part of the T-SQL language and does not work when sent as a command. Workarounds are to send the script using SQLDMO (deprecated), SQLSMO (.NET), a command-line utility, or to parse the GOs out and send each command separately. The sample code below does the latter and uses ADO to send the commands.
Local lcConnString, lcSQLCmd, lcSQLScript, llSuccess
Local loConnection as ADODB.Connection
Local Array laScript[1]

* Connect to SQL Server
TEXT TO lcConnString NOSHOW TEXTMERGE
	Provider=SQLNCLI10;
	Server=MySQLServer;
	Uid=MyUserID;
	Pwd=MyPassword;
	Trusted_Connection=no;
ENDTEXT
loConnection = CreateObject("ADODB.Connection")
Try 
	loConnection.Open(lcConnString)
Catch
	MessageBox('Connection Failed: ' + Chr(13) + Message() + Chr(13) + lcConnString, 16, 'SQL Connect Error')
EndTry 
If loConnection.State <> 1	&& connection not opened
	Return 
EndIf 

* Parse and run script
lcSQLScript = FileToStr("MyScript.sql")
ALines(laScript, lcSQLScript, 8, "GO" + Chr(13))
For each lcSQLCmd in laScript
	Try 
		loConnection.Execute(lcSQLCmd)
		llSuccess = .t.
	Catch
		MessageBox('Error Running Script:' + Chr(13) + Message() + Chr(13) + lcSQLCmd, 16, 'SQL Error')	
		llSuccess = .f.
	EndTry 
	If !llSuccess
		Return
	EndIf 
EndFor 
Joel Leach
Microsoft Certified Professional
Blog: http://www.joelleach.net
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform