Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ignore parameters with SQLExec?
Message
 
To
05/05/2011 17:53:38
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:
01509974
Views:
81
>>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?

What does the actual line of code you're trying to generate look like? Where is the question mark?

It should work within a string constant and using Execute using the indirect expression stored proc I mentioned previously. Give me a reproducable example of what doesn't work.

+++ Rick ---



>>
>
>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 
>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform