Calling a SQL Server stored procedure from Visual Foxpro 9 - sql-server

I have been trying to call a SQL Server stored procedure that has no parameters and no return values. All it does is recalculate data in a SQL Server database.
I thought I could use something simple like
lsqlcmd = " execute storedprocname"
but the procedure is not being called and I am not receiving an errors.
Any suggestions?

Can you try calling it in SQLEXEC()? This how I've seen it done:
TEXT TO lcSQLCommand
<database>.<schema>.<sproc>
ENDTEXT
gcConnectionString = [Driver={SQL Server Native Client 10.0};Server=] + "<servername>" + [;Database=] + "<database>" + [;Trusted_Connection=yes]
STORE SQLSTRINGCONNECT(gcConnectionString) TO gnConnHandle
SQLEXEC(gnConnHandle, lcSQLCommand)
You'll need to update the connection string to however your database is configured, this was for windows authentication.

Related

Stored procedure using PYODBC Not loading destination table in SQL Server

def UploadTable(table):
conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};Server=XXXXXX;Database=XXXXXX;Trusted_Connection=yes')
cur = conn.cursor()
cur.execute("TRUNCATE TABLE dr.Imported_OM01TMP4_Data")
create_statement = fts.fast_to_sql(table, "dr.Imported_OM01TMP4_Data", conn, if_exists="append")
cur.execute("EXEC [dr].[PopulateGlAccountRevenue_Files_UltimateEdition_DeltaLoad]")
conn.commit()
conn.close()
Please see my code snippet above, I am trying to run this stored procedure [dr].[PopulateGlAccountRevenue_Files_UltimateEdition_DeltaLoad] that is already defined in SQL Server.
My code runs fine but when I check to see if the destination table in the server is loaded with the data from the table dr.Imported_OM01TMP4_Data, I am seeing a blank.
When I populate the same table with my python code but execute the stored procedure in SQL Server, the destination table is loaded properly. Is this a permissions / access issue? I have DB Owner Access/Read/Write as well, so I am not sure what is wrong with my code.
Please advise.

The fractional seconds precision issue with PowerBuilder and SQL server 2016

I have a simple stored procedure to return a datetime. e.g:
create procedure sp_get_date (#db_date datetime output)as begin select #db_date ='2017-04-26 13:20:32.313' end
And using SQLNCLI11 native client to work with the datatbase inside the PowerBuilder application.
DECLARE get_date_proc PROCEDURE for dbo.sp_get_date #db_date = :dt_today output using sqlca;
EXECUTE get_date_proc;
FETCH get_date_proc INTO :dt_today;
t_now = time(dt_today)
The expected result for t_now is "13:20:32.313000"
When use SQL sever 2014, the t_now value is correct with 13:20:32.313000
But with SQL server 2016, the value is 13:20:3133333
Is that the problem with native client library to work with SQL server 2016? Is the stored procudure return a datatime2 value?
Thanks a lot.
It looks like you are running into this sql server bug (https://connect.microsoft.com/SQLServer/Feedback/Details/2805477). So it seems the best approach may be to convert the datatype of your parameter to datetime2. Alternatively, it might help to implement the procedure as a RPC in your PB app; I can't really say if that does anything since I'm still using ss 2012.

Determine ODBC database driver from TADOConnection object?

Using Delphi 7 with ADO objects, is it possible to determine the ODBC database driver from the TADOConnection object? So detect whether it is MS-Access or SQL Server or Oracle etc.
The program connects to a database by just using the name of an ODBC data source, and I want to determine whether that database is an MS-Access database or SQL Server. I want to do this because MS-Access and SQL Server use different SQL function names to cast an integer to a string.
The application builds an SQL string which retrieves the VERSION of some configuration objects. It works for SQL server using cast(), but I also want to support MS-Access which uses CStr():
SELECT NAME + '_' + CAST(VERSION as varchar) as OBJECT_NAME FROM ANALYSIS // SQL Server
SELECT NAME + '_' + CStr(VERSION) as OBJECT_NAME FROM ANALYSIS // MS-Access
I've tried looking at the TADOConnection.Provider but that is MSDASQL.1 in both cases.
if (myqry.Connection.Provider = 'MSDASQL.1') then
strSQL := strSQL + 'cast(' + myfieldname + ' as varchar)' // always goes here..
else
strSQL := strSQL + 'CStr(' + myfieldname + ')'; // ..never to here
I've looked at all the TADOConnection properties, but I'm starting to suspect it's not possible. Any ideas how to solve this?
ODBC is designed to abstract away the implementation details of the server. You can use ODBC specific syntax that will be translated to a statement of the appropriate SQL flavour for the server. Here you can substitute :
... { fn CONVERT( VERSION, SQL_VARCHAR ) } AS OBJECT_NAME FROM ANALYSIS
These substitutions are known as ODBC Escape Sequences and can be substituted in queries where there are vendor-specific syntax differences.

VB.Net Upgrade Stored Procedure Call to Oracle Database moRs.Open(moCmd)

I have a program that was written in VB6 and we are trying to convert to VB.Net. When calling stored procedures in Microsoft SQL 2012 and in Oracle using this .Open() method, Microsoft SQL executes fine while Oracle does not. Here is a snippet of code:
Private moRs As ADORecordSetHelper = New ADORecordSetHelper("")
Private moCmd As DbCommand 'where moCmd has the procedure call and parameters
moRs.Open(moCmd)
Here is the definition of .Open()
Public Sub Open(command As System.Data.Common.DbCommand)
Member of UpgradeHelpers.DB.ADO.ADORecordSetHelper
This all works for Microsoft SQL just not with Oracle. I found execute moCmd.ExecuteNonQuery() will work execute the stored procedure, but I need to get the recordset in certain instances as a result.
Is there a way to use moRs.Open(moCmd) for both Microsoft and Oracle? If not, how could I accomplish the same task of getting back the recordsets?
UPDATE: I have figured out that the .Open() method uses Execute Reader which is working fine for the Microsoft SQL that strictly returns a recordset. The Oracle stored procedure is inserting rows and returning values from the procedure. Doing an Execute NonQuery on the same object (moCmd) executes just fine, but all I am able to get from this method is the number of rows affected and not the other information that I need. Thoughts on why the Execture Reader doesn't work? My search says that it should work for all types of SQL; insert, delete, update, etc.

Creating a SQL Server stored procedure in VB.NET

How to create a SQL Server stored procedure in VB.NET by using Imports System.Data.SqlClient?
Public Function createstbkdb()
Return "CREATE PROCEDURE test4444 " + _
+"AS" + _
+"GO"
End Function
Regards,
You can use SqlCommand.ExecuteNonQuery(), passing in the text of your procedure (as queryString in the linked MSDN example).
Note that the connection executing the VB.NET code must have appropriate permissions in the database to create the procedure.
UPDATE
As #CmlJame noted, leave out the "GO". That is meaningful to SSMS but should not be included in the call to ExecuteNonQuery().

Resources