Pass A Variable To A Linked Server (FoxPro) Query

Nov 22, 2004

I'm having problem with an OpenQuery statement in stored procedure, which should be run on FoxPro linked server. I'm getting either an error messages or not the result I expected. I know that the problem is with WHERE part, without this part it works.


Here is the code:
-------------------------------------
DECLARE @LastDate datetime
SELECT @LastDate = MAX(DateChaged)
FROM tblPersonel
WHERE ACTIVE IN( 'A', 'T')

1. I tried:
SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel WHERE DateChanged >=''+@LastDate+''')

This line gives me an error msg:

Could not execute query against OLE DB provider 'MSDASQL'.
[OLE/DB provider returned message: [Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch.]


2. I tried to use CTOD() - FOXPRO function to convert character to date.

SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel WHERE DateChanged >=CTOD(''+@LastDate+'')')

-this doesn't give any error, but doesn't limit the result set as it should.

Thanks all.

View 2 Replies


ADVERTISEMENT

FoxPro Linked Server And Passing Variable Within OPENQUERY

Mar 8, 2005

I'm posting this because I found this solution after much digging.

The goal here is to incorporate a variable parameter within a OPENQUERY and, ultimately build a dynamic Where clause for use within a OPENQUERY linked server routine. I'm posting because I spent a lot of time trying to get this to work and also, have seen other posts here that hinted it wasn't doable.

First of all - there a good quick article that gets close for FoxPro and possibly works as is for ACCESS:

http://support.microsoft.com/default.aspx?scid=kb;en-us;314520

Here's code for a solution:

DECLARE @OPENQUERY nvarchar(4000),
@TSQL nvarchar(4000),
@FAMILY CHAR(10)

SET @FAMILY='Touring'
SET @OPENQUERY = 'SELECT * FROM OPENQUERY(VFP,'''

SET @TSQL = 'select cov,family,model from vinmast where family='+'['+@FAMILY+']'')'

EXEC (@OPENQUERY+@TSQL)

All shown are single quotes.

In Visual Foxpro, ' ' or " " or [ ] can be used a delimeters

In addition, if wanting to build a dynamic where clause, you could do something like:

SET @TSQL = 'select cov,family,model from vinmast '
IF <some condition met to include FAMILY filter>
Begin
SET @TSQL=@TSQL+'where family=['+@DUTFAMILY+']'''
SET @TSQL=@TSQL+ ')'
End
-----------------
Here's the entire Stored Procedure:


CREATE PROCEDURE dbo.ewo_sp_DUTLookup
(
@DUTPROJECT char(25)=NULL,--Project
@DUTFAMILY char(10)=NULL,--Family
@DUTMODEL char(20)=NULL,--Model
@DUTYEAR char(4)=NULL,--Model Year
@DUTBEGIN char(25)=NULL,--Beginning of COV/DUT number
@DEBUG int=0
)


AS

DECLARE @OPENQUERY varchar(4000),
@TSQL varchar(4000),
@TWHERE varchar(4000),
@intErrorCode int

select @intErrorCode = @@ERROR,
@TSQL='',
@TWHERE=''


IF @intErrorCode=0
Begin
SET @OPENQUERY = 'SELECT * FROM OPENQUERY(VFP,'''
SET @TSQL = ' select dut_pk,cov,family,model,project,modelyr from vinmast '
End

set @intErrorCode = @@ERROR

IF @intErrorCode = 0 and
@DUTFAMILY is not NULL or
@DUTMODEL is not NULL or
@DUTPROJECT is not NULL or
@DUTYEAR is not NULL or
@DUTBEGIN is not NULL
set @TWHERE=' where '



-- Check for Family criteria
If @intErrorCode = 0 and @DUTFAMILY is not NULL and Len(@TWHERE)>0
SET @TWHERE=@TWHERE+' family=['+@DUTFAMILY+'] AND '
set @intErrorCode = @@ERROR

-- Check for Model criteria
If @intErrorCode = 0 and @DUTMODEL is not NULL and Len(@TWHERE)>0
SET @TWHERE=@TWHERE+' model=['+@DUTMODEL+'] AND '
set @intErrorCode = @@ERROR

--Check for Project criteria
If @intErrorCode = 0 and @DUTPROJECT is not NULL and Len(@TWHERE)>0
SET @TWHERE=@TWHERE+' project=['+@DUTPROJECT+'] AND '
set @intErrorCode = @@ERROR

--Check for Model Year
If @intErrorCode = 0 and @DUTYEAR is not NULL and Len(@TWHERE)>0
SET @TWHERE=@TWHERE+' modelyr=['+@DUTYEAR+'] AND '
set @intErrorCode = @@ERROR

--Check for beginning of DUT
If @intErrorCode = 0 and @DUTBEGIN is not NULL and Len(@TWHERE)>0
Begin
SET @DUTBEGIN=RTRIM(@DUTBEGIN)
SET @TWHERE=@TWHERE+' substr(cov,1,'+cast(len(@DUTBEGIN) as char(20))+')=['+@DUTBEGIN+'] AND '
End
set @intErrorCode = @@ERROR


IF @intErrorCode=0 AND substring(@TWHERE,Len(@TWHERE)-3,4)=' AND '
Begin
set @TWHERE=Substring(@TWHERE,1,Len(@TWHERE)-3)
select @intErrorCode=@@ERROR
End



SET @TWHERE=@TWHERE+''')'

IF @debug<>0 and @intErrorCode=0
Begin
print @intErrorCode
print @OPENQUERY
print @TSQL
print @TWHERE
print @OPENQUERY+@TSQL+@TWHERE
End

IF @intErrorCode=0
EXEC (@OPENQUERY+@TSQL+@TWHERE)
GO

Peter

View 2 Replies View Related

Severe Error After Installing SQL2005 SP2 Query To Linked Server Foxpro With Oledb

Oct 24, 2007

After installing sql2005 sp2 a simple select query to a linked server reports the following error message:

Msg 0, Level 11, State 0, Line 0A severe error occurred on the current command. The results, if any, should be discarded.Msg 0, Level 20, State 0, Line 0A severe error occurred on the current command. The results, if any, should be discarded.
Before installing SP2 we used sql2005 without any service packs, the linked server worked fine.

The linked server is a Visual FoxPro database.

After uninstalling and installing the 'Microsoft OLE DB Provider for Visual FoxPro 9.0' the issue stil remains.

View 3 Replies View Related

Query Data From The Linked Foxpro Database

Aug 2, 2007

hello,guys,

my question is :
how do I query data from the linked foxpro database?

more:
I have linked a visual foxpro server to my sql server database by using the addserver clause.
Two server is in a local network.
My linked foxpro server named 'fox'.
its datasourse is not a dbc file, but a directory of dbf files ,and its full path is d:foxpro object.
In the directory ,there are three table,'show2003.dbf','sysu.dbf','szszj.dbf'.
And the .dbf files are not in any database.
They are just three files in the same directory.
There is no dbc file.
Now I can see the table list on the right page of the linked server.
But there is something wrong with my sql clause.

sample:

select * from fox..sysu


then the message is:
server: message 7313,level 16,status 1,row 1
the appointed constructure or directory to the provider is inefficacious 'MSDASQL'


I know I may use 'openquery',or 'openrowset'.
The problem is that variable is not valid in 'openquery' and 'openrowset'.
But I must use variable.
so ,please give me some advice.



Thank you very much

View 4 Replies View Related

SQL Server 2012 :: Create Variable In Select Query And Use It In Where Clause To Pass The Parameter

Sep 9, 2014

I am writing a stored procedure and have a query where I create a variable from other table

Declare @Sem varchar (12) Null
@Decision varchar(1) Null
Select emplid,name, Semester
Decision1=(select * from tbldecision where reader=1)
Decision2=(select * from tbldecision where reader=2)
Where Semester=@Sem
And Decision1=@Decision

But I am getting error for Decision1 , Decision2. How can I do that.

View 6 Replies View Related

Linked Server To FoxPro

Nov 5, 2004

Hello,

I want to know if there is an way to SET an index when send a query using the OpenQuery function to a FoxPro database using a linked server in the MS-SQL that points to a System DSN with the MS ODBC Driver to FoxPro.

Thank you in advance,

Aldair.

View 5 Replies View Related

FoxPro Linked Server

Feb 19, 2008

Hi all, I'm having issues with a FoxPro linked server.

I've set up a linked server to a FoxPro dbc using the Microsoft OLE DB Provider for Visual FoxPro. When I'm on Management Studio on my server the link appears to be working fine and a stored procedure I've created to get the indo from the dbc and put it into a temp table works fine.

However, when I try to execute the sp on management studio on my local machine I get the following error:

OLE DB provider "VFPOLEDB" for linked server "tern" returned message "Invalid path or file name.".
Msg 7303, Level 16, State 1, Procedure usp_SSRS_007, Line 28
Cannot initialize the data source object of OLE DB provider "VFPOLEDB" for linked server "tern".

And I also get a similar error when I try to test the connection of the linked server on my local machince.

This is now driving me nuts , so many many thanks in advance for any help!!!

View 4 Replies View Related

Visual FoxPro Linked Server

Jun 19, 2007

I am trying to add a FoxPro linked server to MS SQL 2005, and I can't seam to create a linked server that works. What am I doing wrong in linking the server?



I have an ODBC connection that worked but not OLEDB; how can I do this with OLEDB (either VFPOLEDB or Jet, if it will work) and not ODBC.



This is what I thought was right




Code Snippet

sp_addlinkedserver 'test',

'FoxPro',

'VFPOLEDB',

'C:DataSomeDatabase.dbc',

NULL,

NULL,

NULL



But it gives the error:

Cannot create an instance of OLE DB provider "VFPOLEDB" for linked server "test".



Also I know in MS SQL 2000 once you linked a server you could view it in EM, but when I linked the VFP via ODBC I could query agianst it, but I could not open it in Mangament Studio.



Thank you in advance.

View 11 Replies View Related

Linked Server Query (dependant On Variable)

Nov 27, 2007

Hello,

I hope someone can help me on this one, as I am getting a bit frustrated with my research..

I have procA on ServerA.DatabaseA and it uses an input parameter to get a value that determines which server to ping.

If this parameter is @paramA = 1, then query into LinkedSrvX. If @paramB = 2, then query into LinkedSrvY... etc.

Is there an easier way to do this or a best practice? I really don't want to go into repeating my queries for every server. Here is a tsql mini version of what I am trying to enhance as my original queries are 1000 lines long and I need to get away from the repeated queries. I do have queries that ping within the server and to other linked servers as well without issues.

All linked servers referenced below have the same structure of tables. I also need to avoid situations incase the server may be down, this proc should not return errors.

My Partial Procedure


CREATE PROC procA

@paramA varchar(1) AS


IF (@paramA = '1')


BEGIN



SELECT ColA, ColB

FROM LinkedSrvX.Database0.Owner.Table0

END

IF (@paramA = '2')


BEGIN


SELECT ColA, ColB

FROM LinkedSrvY.Database0.Owner.Table0

END

IF (@paramA = '3')


BEGIN


SELECT ColA, ColB

FROM LinkedSrvZ.Database0.Owner.Table0

END

GO

All ideas / suggestions are welcomed.

Thanks!
-Ashvi

View 5 Replies View Related

Linked Server To Visual FoxPro Not Work

Feb 20, 2005

I've downloaded and installed the latest VFPOLEDB (12/04) on 2 separate SQL Server boxes.

In both cases, If I connect to SQL Server with Query Analyzer as (local) while on a box, the linked server to my foxpro database works fine with openquery().

However, If I'm at one box and attached to SQL Server on the other box, the openquery() fails.

Here's some particulars:
---
EXEC sp_addlinkedserver
@server='VFP',
@provider='VFPOLEDB',
@datasrc='\hdmcpdctis1 isrnddata',
@srvproduct='Visual FoxPro'

--this works on either (local) box
SELECT *
FROM OPENQUERY(VFP, 'select * from tislists')
Go

--but, the same openquery() above doesn't work if the box I'm running it from is attached to the SQL Server on the other box. I get:

Server: Msg 7302, Level 16, State 1, Line 1
Could not create an instance of OLE DB provider 'VFPOLEDB'.
OLE DB error trace [Non-interface error: CoCreate of DSO for VFPOLEDB returned 0x80040154].
=====================
One other approach I tried that works while on the (local) box, but fails when attached to the SQL Server on the other box:

select * from openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;SourceDB= \hdmcpdctis1 isrnddata ',
'select * from [tislists.DBF]')


With error:
Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' reported an error.
[OLE/DB provider returned message: [Microsoft][ODBC Driver Manager] Driver does not support this function]
OLE DB error trace [OLE/DB Provider 'MSDASQL' IDBInitialize::Initialize returned 0x80004005: ].
===========================

Any Help is greatly appreciated! Thanks,

peter :confused:

View 5 Replies View Related

Linked Server For Visual Foxpro (DBF) Table

Jul 13, 2015

I'm running SQL Server 2008 (x64) version.

How can i create a linked server for Microsoft Visual Foxpro databases ?

I'm using Microsoft.ACE.OLEDB.12.0 driver.

I success create a linked server, and can browse all tables from linked server connections, but why when query data using

SELECT * FROM OPENQUERY(PIP_TEST,'select * from tbctrl')

It getting error message

Cannot process the object "select * from tbctrl". The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "pip_test" indicates that either the object has no columns or the current user does not have permissions on that object.

View 6 Replies View Related

How Is Security To FoxPro Managed Through Linked Server From SQL

Sep 14, 2006

I€™ve been working on getting a linked server through SQL 2005 to work with VFP 9.
I get access denied for any and all security set ups on the linked server. I€™ve checked the folder-level security settings and see that the user I€™m logged in as, and have tried through security settings, and they seem to have access.
What other security settings should I be checking?

View 5 Replies View Related

FoxPro OLEDB Driver - Pass Parameters

Feb 2, 2006



Hi,

Does anyone know if the VisualFoxPro 9.0 OLEDB driver supports parameters? Trying to pass parameterised queries from SSIS results in the error reported below, which implies it does support parameters, but that SSIS is not calling the driver properly somehow.

Regards,

Richard

-----------------------------------------------

Error MsgBox:

TITLE: Microsoft Visual Studio
------------------------------

Parameters cannot be extracted from the SQL command. The provider might not help to parse parameter information from the command. In that case, use the "SQL command from variable" access mode, in which the entire SQL command is stored in a variable.

------------------------------
ADDITIONAL INFORMATION:

Provider cannot derive parameter information and SetParameterInfo has not been called. (Microsoft OLE DB Provider for Visual FoxPro)


View 1 Replies View Related

SQL Server 2014 :: Not Able To Pass Value To A Variable

Aug 10, 2014

I've the below query where I am referencing an employee table that has the following structure and has three employee records

IDFIRST_NAMEEMAIL_ADDR
123DONALD DONALD@GMAIL.COM
345MAYANK MAYANKMIN@GMAIL.COM
657MAYANK_NEWMAYANKCGG@GMAIL.COM

I'm passing name of this table (dbO.TD_EmployeeProfile_FinalV2) to get the counts from function FN_COUNT_ROWS (count is 3 as you can see above) so this while loop should run 3 times for all three employees. I'm having issues with statement "SELECT @EMP_ID" and "SELECT @EMAIL"

DECLARE @email varchar(500)
,@intFlag INT
,@INTFLAGMAX int
,@TABLE_NAME VARCHAR(100)
,@EMP_ID INT

[Code] .....

---ERRORS i'm getting
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near ')'.
Msg 102, Level 15, State 1, Line 24
Incorrect syntax near ')'

View 3 Replies View Related

Passing A Variable To A Linked Query (OPENROWSET For Excel Syntax)

May 11, 2007

Hello,

I responded to a very old discussion thread & afraid I buried it too deep.

I have studied the article: How to Pass a Variable to a Linked Query (http://support.microsoft.com/default.aspx?scid=kb;en-us;q314520)



but I have not gotten all the ''''' + @variable syntax right.



Here is my raw openrowset with what I am aiming at.






Code Snippet

-- I want to use some kind of variable, like this to use in the file:

DECLARE @FIL VARCHAR(65)

SET @FIL = 'C:company foldersDocumentationINVENTORY.xls;'

--

SELECT FROM OPENROWSET('MSDASQL', 'Driver=Microsoft Excel Driver (*.xls);DBQ=C:company foldersDocumentationINVENTORY.xls;', 'SELECT * FROM [Inventory$]')

AS DT



Anyone game? Many thank-yous, in advance.



Kind Regards,

Claudia.

View 1 Replies View Related

SSIS: Problem Mapping Global Variables To Stored Procedure. Can't Pass One Variable To Sp And Return Another Variable From Sp.

Feb 27, 2008

I'm new to SSIS, but have been programming in SQL and ASP.Net for several years. In Visual Studio 2005 Team Edition I've created an SSIS that imports data from a flat file into the database. The original process worked, but did not check the creation date of the import file. I've been asked to add logic that will check that date and verify that it's more recent than a value stored in the database before the import process executes.

Here are the task steps.


[Execute SQL Task] - Run a stored procedure that checks to see if the import is running. If so, stop execution. Otherwise, proceed to the next step.

[Execute SQL Task] - Log an entry to a table indicating that the import has started.

[Script Task] - Get the create date for the current flat file via the reference provided in the file connection manager. Assign that date to a global value (FileCreateDate) and pass it to the next step. This works.

[Execute SQL Task] - Compare this file date with the last file create date in the database. This is where the process breaks. This step depends on 2 variables defined at a global level. The first is FileCreateDate, which gets set in step 3. The second is a global variable named IsNewFile. That variable needs to be set in this step based on what the stored procedure this step calls finds out on the database. Precedence constraints direct behavior to the next proper node according to the TRUE/FALSE setting of IsNewFile.


If IsNewFile is FALSE, direct the process to a step that enters a log entry to a table and conclude execution of the SSIS.

If IsNewFile is TRUE, proceed with the import. There are 5 other subsequent steps that follow this decision, but since those work they are not relevant to this post.
Here is the stored procedure that Step 4 is calling. You can see that I experimented with using and not using the OUTPUT option. I really don't care if it returns the value as an OUTPUT or as a field in a recordset. All I care about is getting that value back from the stored procedure so this node in the decision tree can point the flow in the correct direction.


CREATE PROCEDURE [dbo].[p_CheckImportFileCreateDate]

/*

The SSIS package passes the FileCreateDate parameter to this procedure, which then compares that parameter with the date saved in tbl_ImportFileCreateDate.

If the date is newer (or if there is no date), it updates the field in that table and returns a TRUE IsNewFile bit value in a recordset.

Otherwise it returns a FALSE value in the IsNewFile column.

Example:

exec p_CheckImportFileCreateDate 'GL Account Import', '2/27/2008 9:24 AM', 0

*/

@ProcessName varchar(50)

, @FileCreateDate datetime

, @IsNewFile bit OUTPUT

AS

SET NOCOUNT ON

--DECLARE @IsNewFile bit

DECLARE @CreateDateInTable datetime

SELECT @CreateDateInTable = FileCreateDate FROM tbl_ImportFileCreateDate WHERE ProcessName = @ProcessName

IF EXISTS (SELECT ProcessName FROM tbl_ImportFileCreateDate WHERE ProcessName = @ProcessName)

BEGIN

-- The process exists in tbl_ImportFileCreateDate. Compare the create dates.

IF (@FileCreateDate > @CreateDateInTable)

BEGIN

-- This is a newer file date. Update the table and set @IsNewFile to TRUE.

UPDATE tbl_ImportFileCreateDate

SET FileCreateDate = @FileCreateDate

WHERE ProcessName = @ProcessName

SET @IsNewFile = 1

END

ELSE

BEGIN

-- The file date is the same or older.

SET @IsNewFile = 0

END

END

ELSE

BEGIN

-- This is a new process for tbl_ImportFileCreateDate. Add a record to that table and set @IsNewFile to TRUE.

INSERT INTO tbl_ImportFileCreateDate (ProcessName, FileCreateDate)

VALUES (@ProcessName, @FileCreateDate)

SET @IsNewFile = 1

END

SELECT @IsNewFile

The relevant Global Variables in the package are defined as follows:
Name : Scope : Date Type : Value
FileCreateDate : (Package Name) : DateType : 1/1/2000
IsNewFile : (Package Name) : Boolean : False

Setting the properties in the "Execute SQL Task Editor" has been the difficult part of this. Here are the settings.

General
Name = Compare Last File Create Date
Description = Compares the create date of the current file with a value in tbl_ImportFileCreateDate.
TimeOut = 0
CodePage = 1252
ResultSet = None
ConnectionType = OLE DB
Connection = MyServerDataBase
SQLSourceType = Direct input
IsQueryStoredProcedure = False
BypassPrepare = True

I tried several SQL statements, suspecting it's a syntax issue. All of these failed, but with different error messages. These are the 2 most recent attempts based on posts I was able to locate.
SQLStatement = exec ? = dbo.p_CheckImportFileCreateDate 'GL Account Import', ?, ? output
SQLStatement = exec p_CheckImportFileCreateDate 'GL Account Import', ?, ? output

Parameter Mapping
Variable Name = User::FileCreateDate, Direction = Input, DataType = DATE, Parameter Name = 0, Parameter Size = -1
Variable Name = User::IsNewFile, Direction = Output, DataType = BYTE, Parameter Name = 1, Parameter Size = -1

Result Set is empty.
Expressions is empty.

When I run this in debug mode with this SQL statement ...
exec ? = dbo.p_CheckImportFileCreateDate 'GL Account Import', ?, ? output
... the following error message appears.

SSIS package "MyPackage.dtsx" starting.
Information: 0x4004300A at Import data from flat file to tbl_GLImport, DTS.Pipeline: Validation phase is beginning.

Error: 0xC002F210 at Compare Last File Create Date, Execute SQL Task: Executing the query "exec ? = dbo.p_CheckImportFileCreateDate 'GL Account Import', ?, ? output" failed with the following error: "No value given for one or more required parameters.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Task failed: Compare Last File Create Date

Warning: 0x80019002 at GLImport: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

SSIS package "MyPackage.dtsx" finished: Failure.

When the above is run tbl_ImportFileCreateDate does not get updated, so it's failing at some point when calling the procedure.

When I run this in debug mode with this SQL statement ...
exec p_CheckImportFileCreateDate 'GL Account Import', ?, ? output
... the tbl_ImportFileCreateDate table gets updated. So I know that data piece is working, but then it fails with the following message.

SSIS package "MyPackage.dtsx" starting.
Information: 0x4004300A at Import data from flat file to tbl_GLImport, DTS.Pipeline: Validation phase is beginning.

Error: 0xC001F009 at GLImport: The type of the value being assigned to variable "User::IsNewFile" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

Error: 0xC002F210 at Compare Last File Create Date, Execute SQL Task: Executing the query "exec p_CheckImportFileCreateDate 'GL Account Import', ?, ? output" failed with the following error: "The type of the value being assigned to variable "User::IsNewFile" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Compare Last File Create Date

Warning: 0x80019002 at GLImport: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (3) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

SSIS package "MyPackage.dtsx" finished: Failure.

The IsNewFile global variable is scoped at the package level and has a Boolean data type, and the Output parameter in the stored procedure is defined as a Bit. So what gives?

The "Possible Failure Reasons" message is so generic that it's been useless to me. And I've been unable to find any examples online that explain how to do what I'm attempting. This would seem to be a very common task. My suspicion is that one or more of the settings in that Execute SQL Task node is bad. Or that there is some cryptic, undocumented reason that this is failing.

Thanks for your help.

View 5 Replies View Related

FoxPro Triggers Call FoxPro Stored Proc Calls SQL Server Stored Procedure

Mar 10, 2005

I didn't want to maintain similar/identical tables in a legacy FoxPro system and another system with SQL Server back end. Both systems are active, but some tables are shared.

Initially I was going to use a Linked Server to the FoxPro to pull the FP data when needed. This works. But, I've come up with what I believe is a better solution. Keep in mind that these tables are largely static - occassional changes, edits.

I will do a 1 time DTS from FP into SQL Server tables.

I then create INSERT and UPDATE triggers within FoxPro.

These triggers fire a stored procedure in FoxPro that establishes a connection to the SQL Server and fire the appropriate stored procedure on SQL Server to CREATE and/or UPDATE the corresponding table there.

In the end - the tables are local to both apps.

If the UPDATES or TRIGGERS fail I write to an error log - and in that rare case - I can manually fix. I could set it up to email me from within FoxPro as well if needed.

Here's the FoxPro and SQL Server code for reference for the Record Insert:

FOXPRO employee.dbf InsertTrigger:
employee_insert_trigger(VAL(Employee.ep_pk),Employ ee.fname,Employee.lname,Employee.email,Employee.us er_login,Employee.phone)

FOXPRO corresponding Stored Procedure:
FUNCTION EMPLOYEE_INSERT_TRIGGER
PARAMETERS wepk,wefname,welname,weemail,WEUSERID,WEPHONE

nhandle=SQLCONNECT('SS_PDITHP3','userid','password ')

IF nhandle<0
m.errclose=.f.
IF !USED("errorlog")
USE tisdata!errorlog IN SELECT(1)
m.errclose=.t.
ENDIF

SELECT errorlog
INSERT INTO errorlog (date, time, program,source,user) ;
values (DATE(), TIME(), 'EMPLOYEE_INSERT_TRIGGER','nhandle<0 PARAMS: '+STR(wepk)+wefname+welname+weemail+WEUSERID+WEPHO NE,GETENV("username"))

IF m.errclose
USE IN errorlog
ENDIF
RETURN

ENDIF
nquery="exec ewo_sp_insertNewEmployee @WEPK ="+STR(wepk)+",@WEFNAME ='"+wefname+"',@WELNAME ='"+welname+"',@WEEMAIL ='"+weemail+"',@WEUSERID ='"+weuserid+"',@WEPHONE='"+wephone+"',@RETCODE =0"
nsucc=SQLEXEC(nhandle,nquery)

SQLDISCONNECT(nhandle)

IF nSucc<0
m.errclose=.f.
IF !USED("errorlog")
USE tisdata!errorlog IN SELECT(1)
m.errclose=.t.
ENDIF

SELECT errorlog
INSERT INTO errorlog (date, time, program,source,user) ;
values (DATE(), TIME(), 'EMPLOYEE_INSERT_TRIGGER','nSucc<0 PARAMS: '+STR(wepk)+wefname+welname+weemail+WEUSERID+WEPHO NE,GETENV("username"))

IF m.errclose
USE IN errorlog
ENDIF
ENDIF

RETURN

SQL SERVER Stored Procedure called from FOXPRO Stored Procedure
CREATE procedure ewo_sp_insertNewEmployee (
@WEPK int,
@WEFNAME char(20),
@WELNAME char(20),
@WEEMAIL char(50),
@WEUSERID char(15),
@WEPHONE char(25),
@RETCODE int OUTPUT
)

AS

insert into WO_EMP (
WE_PK,
WE_FNAME,
WE_LNAME,
WE_EMAIL,
WE_USERID,
WE_PHONE
)

VALUES (
@WEPK,
@WEFNAME,
@WELNAME,
@WEEMAIL,
@WEUSERID,
@WEPHONE
)


IF @@ERROR <> 0
BEGIN
SET @RETCODE=@@ERROR
END
ELSE
BEGIN
-- SUCCESS!!
SET @RETCODE=0
END

return @RETCODE
GO

View 2 Replies View Related

Query Server Error When Accessing Visual FoxPro 9.0 Via ODBC

Nov 6, 2007



I have a report that accessed a Visual FoxPro 6.0 database via ODBC. Since I upgraded to Visual FoxPro 9.0, now I am getting the error:

Query Server Error
DMS-E-RBI_TABLE The table or view <table name> was not found in the dictionary

I've verified that the right path is setup and I've tried installing about every driver and none of them are working. I created a new database in 9.0 and the I can access it fine. Also, there are old tables that are accessible in the same path, just not the ones I need. Any ideas would be helpful..

View 1 Replies View Related

Upload File - Pass Variable - Fire DTS Sql Server 2000

Jul 31, 2006

Hi All,
I am looking to do the following:
1) Upload a text file via a website to a server with sql server 2000.
2) Fire a DTS package on that file so it appends the contents to a table in the database.
3) Choose a variable via a dropdown list on the website
4) Run a different DTS Package that uses an update sql statement that uses that Variable.
Any help or suggestions would be greatly appreciated.
Thanls,
Doug
 

View 6 Replies View Related

Passing A Linked Server As A Variable?

May 25, 2006

Anyone got any Ideas on how to set tax...TXZip as a variable in the following script segment?



Select
RecordID = Identity(int,1,1),
Zip_ZipCode,
Zip_SignatureCode
Into #Temp
from tempstatezip
where State = @State

Delete From tax...TXZIP ------------------------------

While (Select Count(*) from #temp)>0
Begin

Set @rowVal = (Select top 1 RecordID from #Temp)


Id like to set this up in a store procedure so I can pass the state variable to it.....

Having problems setting a linked server as a variable thou.....
Example of what I want.....
Delete from @StateVar
But as a linked server I always get...

declare @StateVar Varchar(11)
Set @StateVar = 'Tax...TXZip'
Select * from @StateVar

Msg 137, Level 15, State 2, Line 3
Must declare the variable '@StateVar'.

Any Ideas?

View 2 Replies View Related

Linked Servers And Pass-Through Queries

Apr 6, 2000

Is there a way that I can prevent people from running
pass through queries on my SQL Server - without
removing linked server access? I simply want to make
sure that the processing occurs on the clients machine,
not on my server....

Thanks!

Dean

View 1 Replies View Related

Pass Variable

Aug 8, 2007

Hello,
I placed a post regarding this issue previously but no success. So I thought I explain everything properly this time in a new post. Thanks

I have created a stored procedure which passes variables to the ssis package and then executes the package.
The two variables inside the ssis package are @FileName and @ConnectionPath
As you can see from the below stored procedure, xp_cmdshell is used to execute the package.
If only the first variable is used in the package and the @connectionPath variable is hardcoded inside the package then package runs fine.
Problem is in this particular call as you see below because @ConnectionPath is included.

The output of print is:

dtexec /f d:sysapplCEMSSISImportsTradesBaseProfiles2.dtsx /set Package.Variables[User::FileName].Properties[Value];"d:ApplDataCEMWorkingTempprofiles.csv"
/set Package.Variables[User::ConnectionPath].Properties[Value];"Data Source=servername1instancename1, 2025;Initial Catalog=CounterpartyExposure;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;"


Error is:

Error: 2007-08-08 08:46:01.29
Code: 0xC0202009
Source: BaseProfiles2 Connection manager "CounterpartyExposure"
Description: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft OLE DB Provider for ODBC Drivers" Hresult: 0x80004005 Description: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
End Error


if only the output is run in the query analyser then the error is:

The identifier that starts with 'Data Source=gblond088sjyMSQL_curves_DEV1, 2025;Initial Catalog=CounterpartyExposure;Provider=SQLNCLI.1;Integrated Security=SSPI' is too long. Maximum length is 128.



/*********************************************************************************

uspCEMTradeExecutePackage2 'd:sysapplCEMSSISImportsTradesStaticMappingOverride.dtsx',
'StaticMappingOverride.csv',
'Data Source=servername1instancename1, 2025;Initial Catalog=CounterpartyExposure;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;'
*********************************************************************************/

ALTER procedure [dbo].[uspCEMTradeExecutePackage2]

@FullPackagePath varchar(1000),
@FileName varchar(500),
@ConnectionPath varchar(1000)


as

declare @returncode int
declare @cmd varchar(1000)

declare @FilePath varchar(1000)
declare @FullFilePath varchar(1000)

set @FilePath = 'd:ApplDataCEMWorkingTemp'
set @FullFilePath = @FilePath + @FileName
print ' ----------- ' + @FileName

set @cmd = 'dtexec /f ' + @FullPackagePath + ' /set Package.Variables[User::FileName].Properties[Value];"' + @FullFilePath + '"'
set @cmd = 'dtexec /f ' + @FullPackagePath +
' /set Package.Variables[User::FileName].Properties[Value];"' + @FullFilePath + '"
/set Package.Variables[User::ConnectionPath].Properties[Value];"' + @ConnectionPath + '"'

print @cmd

set nocount on

begin try

exec @returncode = master..xp_cmdshell @cmd

end try

begin catch

exec @LastGoodVersionSP

DECLARE @msg nvarchar(200)
SET @msg = ('Error during execute package')

EXECUTE uspErrorReporter @msg
end catch

set nocount off

View 1 Replies View Related

Pass Linked ServerName To A Cursor Issue...

Jun 18, 2002

Need to loop through a Cursor to linked server:
-----------------------------------------------
Declare Cursor_Loop_serverName Cursor for
select cast(name as varchar(30)) name, cast(dbID as varchar(5)) dbID,
cast(crdate as varchar(25)) crdate
from ServerName_A.master.dbo.sysdatabases

***How could I pass @serverName to change the from to
from @RemoteServer.master.dbo.sysdatabases?
I have tried dynamic sql, it did not work after the Declare Cursor for...

thanks for the help
David

View 2 Replies View Related

How To Pass A Variable Like 'Santhosh'

Dec 10, 2007

Hi
I have a stored procedure which will do some thing like this
create proc xxx
(
@useralias varchar(32)
)
set @useralias = '''' +  @useralias + '''';
select * from users where useralias =  @useralias
EX: Select * from users where useralias = 'Santhosh'. But, when i give the query like this
EXec xxx santhosh
It gives the error message ...no column by name santhosh or Invalid column. So, i thought i will pass the same from the UI
EX:
string str = "'" +  santhos + "'".
But, the probem with this is, it is not giving any results.
So, how do i get around with this prob?
Thanks!
Santhosh

View 2 Replies View Related

How Do I Pass Variable Into DTS Package?

Nov 20, 2001

I have a SQL 7 package which uses a select statement. Within the the select statement is
a where clause. I would like to define a string variable for the object of the where clause. I would
like to have this string variable passed into the package just prior to execution of the package.

Anyone know how to do this?

Thanks in advance for the help!!!!!

Gary Andrews
andrews_gary_w@solarturbines.com

View 2 Replies View Related

T-SQL (SS2K8) :: Trying To Pass A Value To A Variable

May 4, 2015

I am trying to do the following:

DECLARE @MinBoundary DateTime, @s nvarchar(max)
declare @DBName sysname, @TableName sysname
select @DBName = 'MyDB', @TableName = 'MyTable'
select @s = '
SELECT Convert(DateTime, MIN(PRV.value))

[Code] ...

It works if I print @s query and run it this way, so the query is correct):

DECLARE @MinBoundary DateTime
SELECT @MinBoundary = Convert(DateTime, MIN(PRV.value))
FROM sys.partition_functions AS PF
JOIN sys.partition_parameters AS PP
ON PF.function_id = PP.function_id

[Code] ....

View 6 Replies View Related

How To Pass Value To Bind Variable

Jun 19, 2008

select field1 from table1 where field1 = @p_field1

Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@p_field1".

Hi, i'm getting this error, could anybody please explain, how the syntax should be.........thanks

View 8 Replies View Related

How To Pass A Variable Into In Operator

Jul 19, 2006

How can i execute this query thru Stored procedure ?

delete from ts_imported where ts_imported.c_change_symbol in ('A','B')

Symbols ('A','B') varies
How to pass this in paramter


I tried this

declare @Symbol varchar(20)
declare @apos char(1)
set @apos=''''

set @Symbol = @apos +'A' + @apos + ',' + @apos + 'B' + @apos
delete from ts_imported where c_change_symbol in (@Symbol)

Doesn't produce correct output!

View 7 Replies View Related

Pass Variable With A Space

Jul 31, 2007

Hi,
I am passing a filename to a command in sql.
The problem is that it gives an error if the @FullFilePath has a space in it.


set @cmd = 'dtexec /f ' + @FullPackagePath + ' /set Package.Variables[User::FileName].Properties[Value];' + @FullFilePath + '"'

print @cmd


Thanks

View 4 Replies View Related

How To Pass SourceConnectionFlatFile From A Variable?

Apr 20, 2007

Hello,

In my Data Flow Task, I have a Flat File source that I would like to use a variable. How do I accomplish that? I tried it in Advanced Editor & Connection Managers, but not sure where I could slide my variables for it to be recognized.



Any help is appreciated,

-Lawrence

View 7 Replies View Related

How To Pass A Variable To The Stored Procedure?

Feb 22, 2007

Hi,
i need to insert a record 1 or more times, depending of a variable in code-behind:dim amount as integeramount= value (e.g. 3)
My problem is: how to pass that variable to the stored procedure?I tried with this but nothing happens:
comd.Parameters.Add("@amount", SqlDbType.NVarChar, 10).Value = amount_of_details
Maybe is my stored procedure wrong?
Thanks
T.
Here is it:----------
ALTER PROCEDURE dbo.insert_table (@field1 nvarchar(10),...)ASDeclare @iLoopNumber intDeclare @amount intBEGIN TRAN
SET @iLoopNumber = 1
SET @amountr
While (@iLoopNumber <= @amount)
BEGIN
INSERT INTO table(field1,...)
VALUES (....))
 SET @iLoopNumber = @iLoopNumber +1
End
COMMIT TRAN
 

View 3 Replies View Related

Update SQL Variable Pass Problem

Sep 27, 2005

Sorry to bother you.
 
I am trying to create an Update Form. There is only one Field that can be edited on this form – agencydesc  (Agency Description).  I’m trying to perform the update to the Database the .Net way and I am definitely having some trouble. The form is loaded from the file AgencyEdit.aspx. An Image Button does a Server.Transfer to AgencyUPD.aspx where the update is completed. When AgencyEdit.aspx is loaded the Agency Description is pre-populated in TextBox1. When the value of TextBox1 is changed, the change does not show when the variable is passed to AgencyUPD.aspx, the value remains the initial populated value from the Database. Any help would greatly be appreciated.
 
Relevant CS Code from AgencyEdit.aspx
 
      public string myBase;
      public int eSernum;
      public string eAgency;
      public string eDesc;
      protected System.Web.UI.WebControls.ImageButton ImageButton3;
      protected System.Web.UI.WebControls.TextBox TextBox1;
       
      public string myTest
      {
            get {return this.TextBox1.Text;}
      }
       
      private void Page_Load(object sender, System.EventArgs e)
      {
      string myUrl = Application.Contents["Base"] + Common/Login.aspx";
      if (Session["isLogged"] == null) Response.Redirect(myUrl);
           
      myBase = Application.Contents["Base"].ToString();
      int mySernum = Int32.Parse(Request.QueryString["sernum"]);
           
SqlConnection con1 = new SqlConnection(Application.Contents["EwsConnectionString"].ToString());
      SqlDataReader drsLog1;
      SqlCommand cmd1 = new SqlCommand();
 
      con1.Open();
       
      cmd1.CommandText = "SELECT * FROM ewsagencies WHERE sernum = " + mySernum;
      cmd1.Connection = con1;
      drsLog1 = cmd1.ExecuteReader(CommandBehavior.CloseConnection);
       
      while (drsLog1.Read())
       {
       eSernum = drsLog1.GetInt32(0);
       eAgency = drsLog1.GetString(1);
       if (!drsLog1.IsDBNull(2)) eDesc = drsLog1.GetString(2);
       }
      con1.Close();
      this.TextBox1.Text = eDesc;  
      }
 
      private void ImageButton3_Click(object sender, System.Web.UI.ImageClickEventArgs e)
      {
       Server.Transfer("AgencyUPD.aspx");
      }
 
 
Relevant CS Code from AgencyUPD.aspx
 
 
namespace VWeb.vAdmin.Agencies
{
 public class AgencyUPD : System.Web.UI.Page
 {
   public AgencyEdit SourcePage;
  
private void Page_Load(object sender, System.EventArgs e)
      {
      AgencyEdit SourcePage = (AgencyEdit) Context.Handler;
      int mySernum = SourcePage.eSernum;
      string myDesc = SourcePage.myTest;
 
SqlConnection conUpdate = new SqlConnection(Application.Contents["EwsConnectionString"].ToString());
      SqlCommand cmd1 = new SqlCommand();
 
      conUpdate.Open();
       
      cmd1.CommandText = "UPDATE ewsagencies SET agencydesc = @desc WHERE sernum = " + mySernum;
      cmd1.Parameters.Add("@desc", SqlDbType.VarChar).Value = myDesc;
      cmd1.Connection = conUpdate;
 
      cmd1.ExecuteNonQuery();
 
      conUpdate.Close();
      string myUrl = Application.Contents["Base"] + "vAdmin/Agencies/AgencyList.aspx";
      Response.Redirect(myUrl);
}
 
            #region Web Form Designer generated code .. etc.
      }
}
 
 
 

View 1 Replies View Related

Can Is Pass Tablename In SQL Stmt As Variable

Jul 1, 1999

I am trying to create a stored procedure for automating Bulk inserting into tables
for one database to another.
Is there any way i can pass the table name as variable to insert and select stmt


thanks in advance

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved