SQL Server Pass Through for Drop Table (1 Viewer)

Rx_

Nothing In Moderation
Local time
Today, 04:28
Joined
Oct 22, 2009
Messages
2,803
Two Questions below:
Explanation: My Linked Tables has a Persist table that just keeps a live connection. The Connection information is in line 50. The SQLDBName has two versions 1.) SQLDBName for Production and SQLDBNameT for Testing.
The goal was to have what ever version running pull the correct connection string for the Database's Stored Procedure.

Question: if the table is not there, it shows an error in VBA. The error isn't welcome, do I just comment out the RaiseError?
Code:
-- Drop a Well Name pass in as parameter    Create SP code
USE SQLDBName
GO 
CREATE PROCEDURE dbo.NVLinked_DROPTABLE( 
                @TableToDrop SYSNAME) 
AS 
  IF EXISTS (SELECT 1 
             FROM   INFORMATION_SCHEMA.TABLES 
             WHERE  TABLE_SCHEMA = 'dbo' 
                    AND TABLE_NAME = @TableToDrop) 
    BEGIN 
      DECLARE  @Drop NVARCHAR(MAX) 
      SET @Drop = 'DROP TABLE ' + QUOTENAME(@TableToDrop) 
      EXECUTE( @Drop); 
    END 
  ELSE 
    RAISERROR ('Table to drop "%s" does not exist in the current database!',16,1,@TableToDrop);
GO
will add a string parameter to this subroutine so it works with 12 tables
Question:
For 12 tables - should I loop, or just call DropTAble_storedProcCall 12 times so the Process has time to complete?
Code:
Sub DropTAble_StoredProcCall()
      Dim SqlPassThrough As String
      ' Calls SP - Deletes SQL Table - calls Oracle Pass Through Server - Recreates SQL Table NV_WELL_DEN_VIEW
            Dim qdf As DAO.QueryDef
            Dim dbs As DAO.Database
10    On Error GoTo Errortrap
20          Set dbs = CurrentDb()
30            Set qdf = dbs.CreateQueryDef(vbNullString)
40            SqlPassThrough = "[NVLinked_DROPTABLE] NV_WELL_DEN_VIEW;"
50            qdf.Connect = CurrentDb.TableDefs("PersistConn").Connect ' comes from DSNLess setting of Production or Test database
60            qdf.ReturnsRecords = False
70            qdf.SQL = SqlPassThrough
80            qdf.Execute ', dbSQLPassThrough       'dbFailOnError  'I also tried without dbFailOnError - gave up on both
90            SqlExecute = qdf.RecordsAffected  'This returns the number for the LAST LOCAL (Jet) query run, not the current (pass thru).
100           qdf.Close
110           Set qdf = Nothing
120   Exit Sub
Errortrap:
130       MsgBox "error is " & Err.Number & " " & Err.Description
End Sub
There is similar code that makes a SQL Server table (SqlPassThrough = "EXEC [sp_LinkedServer-MakeTableA_NV_WELL_DEN_VIEW];")
It is made from an Oracle Linked Server.
For what ever reason (VPN, Oracle, ...) the Oracle data is dreadfully slow. Running a simple Query with Where clause in SSIS takes over two minutes.

The plan is to run a Job early morning and copy 12 tables into SQL Server. Oracle is Read-Only anyway. For emergencies, there will be a VBA "Run it now" option that Drops 12 tables, then re-- Creates 12 Tables.
I still have to figure out how to keep multi-users out for the dreadful 15 minutes it takes to refresh these 12 tables.

(this code is working)
 

Users who are viewing this thread

Top Bottom