Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Location
    Romania
    Posts
    1

    Unanswered: error handling OPENROWSET

    If, for example, i have inside a procedure the next statement:
    EXEC ('SELECT TOP 0 id1 as id1, *
    FROM OPENROWSET(''MSDASQL'', ''Driver={Microsoft Visual FoxPro Driver};
    UID=;PWD=;SourceDB=' + @path + ';
    SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;
    Collate=Machine;Null=Yes;Deleted=Yes;'', ''
    SELECT * FROM ' + @file + '
    '')')

    in some ocasions it will generate errors
    - if no file or path,
    - if no column, ...
    how can i handle those errors and continue the procedure without generating an error.

  2. #2
    Join Date
    Jan 2003
    Location
    New York
    Posts
    160
    Error for "no column" when does that occur ? Only way i cna think of is if the file doe not exist.

    To check if the file or path exists

    declare @Path varchar(128)
    declare @FileName varchar(10)

    --i used 10 chars because foxpro2.6 allows only length of 10 for a filename and i am not sure what visual fp uses (also fp2.6 doesn't like spaces in path if that matters in your situation)

    select @Path = 'C:\', @FileName = 'myfile.dbf'
    declare @i int
    declare @File varchar(1000)

    select @File = @Path + @FileName
    exec master..xp_fileexist @File, @i out
    if @i = 1
    EXEC ('SELECT TOP 0 id1 as id1, *
    FROM OPENROWSET(''MSDASQL'', ''Driver={Microsoft Visual FoxPro Driver};
    UID=;PWD=;SourceDB=' + @path + ';
    SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;
    Collate=Machine;Null=Yes;Deleted=Yes;'', ''
    SELECT * FROM ' + @file + ''')')
    else
    print 'no file'
    Beyond Limitation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •