I have a VBA macro that kicks off a SQL Server stored procedure. During development all was well, until we added code to the stored proc to take a before/after snapshot of changes made. Without modifying the VBA macro, if we remove the CREATE TABLE code, the macro works fine. If we include it, it crashes with an 8004E021 error. We've tried creating the table both in memory and on disk; behavior is the same.
Is there a setting on SQL Server, or in Excel/VBA that we're missing?
5 1741 Rabbit 12,516
Recognized Expert Moderator MVP
There's not nearly enough information to diagnose the problem.
What's the macro code?
What's the stored procedure code?
What's the full error text?
Is it an Excel error or SQL Server error?
Does the stored procedure with the create table statment run outside of Excel, say in SSMS?
@Rabbit
Sorry -- I debated how much detail to get into, and apparently I erred too much on the lean side.
What's the macro code?
--------------------- - cnnConnect.Open "Provider=SQLOLEDB.1;Initial Catalog=" & dbnShort _
-
& ";Data Source=myservername;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;" _
-
& "Use Encryption for Data=False;Tag with column collation when possible=False;" _
-
& "User ID=myuserid;Password=mypassword;"
-
-
Set rstRecordset = New ADODB.Recordset
-
-
rstRecordset.Open _
-
Source:="exec DB_GLOBAL.dbo.[USR_Cred2_DisplayUncompletedCreds-Excel] '" _
-
& dbnShort & "', '" & DBList(idxDB, 2) & "'", _
-
ActiveConnection:=cnnConnect, _
-
CursorType:=adOpenDynamic, _
-
LockType:=adLockReadOnly, _
-
Options:=adCmdText
-
-
'Add the new QueryTable to the new worksheet and populate it from rstRecordset
-
With ActiveSheet.QueryTables.Add( _
-
Connection:=rstRecordset, _
-
Destination:=Range(wsName & "!A6"))
-
-
.Name = "BLSQL1_" & wsName
-
.FieldNames = True
-
.RowNumbers = False
-
.FillAdjacentFormulas = False
-
.PreserveFormatting = True
-
.RefreshOnFileOpen = False
-
.BackgroundQuery = False
-
.RefreshStyle = xlInsertEntireRows
-
.SavePassword = True
-
.SaveData = True
-
.AdjustColumnWidth = True
-
.RefreshPeriod = 0
-
.PreserveColumnInfo = True
-
.Refresh (False)
-
End With
What's the stored procedure code?
--------------------------------
The Stored Procedure code is lengthy, but the CREATE TABLE portion is as follows. This is the section that, when commented out, works fine, but fails when left in. This SQL code runs correctly when run on the server; it is only when called from Excel that it fails:
----------------- - SET @cmdlogs = 'USE ' + @db + ' '
-
+ 'IF OBJECT_ID(''USR_LN_UPDATE_BEFORE'') is null '
-
+ 'BEGIN '
-
+ 'CREATE TABLE [dbo].[USR_LN_UPDATE_BEFORE]('
-
+ '[rundate] [datetime] NOT NULL,'
-
+ '[db] [varchar](40) NOT NULL,'
-
+ '[mcid] [varchar](12) NOT NULL,'
-
+ '[CusAddrID] [numeric](12, 0) NOT NULL,'
-
+ '[Cred] [varchar](100) NULL,'
-
+ '[Creds] [varchar](40) NULL,'
-
+ '[Creds Desc] [varchar](40) NULL,'
-
+ '[Cust LN] [varchar](80) NULL,'
-
+ '[Cad LN] [varchar](80) NULL,'
-
+ '[Fmt Dtl] [varchar](400) NULL,'
-
+ '[Srch Name] [varchar](80) NULL,'
-
+ '[Script Name] [varchar](255) NULL) '
-
+ 'GRANT ALTER ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
-
+ 'GRANT DELETE ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
-
+ 'GRANT INSERT ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
-
+ 'GRANT SELECT ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
-
+ 'GRANT UPDATE ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
-
+ 'END '
-
+ 'IF OBJECT_ID(''USR_LN_UPDATE_AFTER'') is null '
-
+ 'BEGIN '
-
+ 'CREATE TABLE [dbo].[USR_LN_UPDATE_AFTER]('
-
+ '[rundate] [datetime] NOT NULL,'
-
+ '[db] [varchar](40) NOT NULL,'
-
+ '[mcid] [varchar](12) NOT NULL,'
-
+ '[CusAddrID] [numeric](12, 0) NOT NULL,'
-
+ '[Cred] [varchar](100) NULL,'
-
+ '[Creds] [varchar](40) NULL,'
-
+ '[Creds Desc] [varchar](40) NULL,'
-
+ '[Cust LN] [varchar](80) NULL,'
-
+ '[Cad LN] [varchar](80) NULL,'
-
+ '[Fmt Dtl] [varchar](400) NULL,'
-
+ '[Srch Name] [varchar](80) NULL,'
-
+ '[Script Name] [varchar](255) NULL) '
-
+ 'GRANT ALTER ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
-
+ 'GRANT DELETE ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
-
+ 'GRANT INSERT ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
-
+ 'GRANT SELECT ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
-
+ 'GRANT UPDATE ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
-
+ 'END '
What's the full error text?
--------------------------
It is the very informative "System Error 8004E021" that appears in a popup messagebox whenever there is some difficulty between Excel and SQL Server. Separately, I've found a table that says this error refers to a field being "too small to accept the amount of data you attempted to add." However, I've verified all field lengths in the CREATE code, and I'm not adding data from Excel -- only kicking off a stored proc. Since I can run the SQL successfully on the server, I can't see where such an error comes from.
Is it an Excel error or SQL Server error?
----------------------------------------
Hard to tell. I believe Excel is responding with the "System Error" messagebox based on something happening on the SQL side (since it only happens when the CREATE code is present in the stored proc).
Does the stored procedure with the create table statment run outside of Excel, say in SSMS?
-----------------------------------
Yes, it runs on a server dedicated to running SQL Server. I wouldn't say it runs "in SSMS", since Excel doesn't open an SSMS session -- it simply makes a connection (see the connection object in the VBA code). However, your question may be answered by the fact the the SQL code runs successfully when executed directly from an SSMS session.
Thanks for bearing with me this far...
Any ideas?
Rabbit 12,516
Recognized Expert Moderator MVP
Please use code tags when posting code or formatted data.
Is the user credentials in the macro connection the same one you use to log into the SQL Server outside of Excel? My guess is that there are missing permissions for the user.
Thanks, Rabbit. That appears to be the issue. Had looked at the permissions at the beginning of troubleshooting , but apparently missed an important setting. Your pointing me back to permissions was an excellent idea -- thanks!
Rabbit 12,516
Recognized Expert Moderator MVP
No problem, glad you got it working!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: P |
last post by:
I would like to call my stored proc and invoke the WITH RECOMPILE
option. I can't figure out what to set in ADO to make that happen.
Anyone know how to make this work? BTW, I _don't_ want to create the
stored proc using the WITH RECOMPILE.
|
by: HumanJHawkins |
last post by:
Hi,
I am using data from multiple databases and/or queries. It would greatly
simplify and speed things up if I could use CONTAINS in processing the
results. However, "CONTAINS" requires the data to be indexed. Due to the
amount of processing, I think it would be faster even if I had to re-index
every time.
For example, I would like to do something like this (simplified to
illustrate the desired functionality... This should show all of...
|
by: Brad H McCollum |
last post by:
I've looked through many suggestions and partial examples all over
this newsgroup and still am not coming up with anything that does
specifically what I'm wanting to accomplish.
I'm writing a VB 6.0 application which uses SQL Server as the
back-end.
Here's an example of what I'm wanting to do...
A user accessing the VB GUI attempts to open a certain form. Code
|
by: Jack Black |
last post by:
Help!! I'm trying to call a custom stored procedure from a VB.Net
code-behind page in an ASP.Net application, and I keep getting an
error with no real helpful info...
Basically, I'm accepting a username and password from a front-end, and
performing a simple INSERT into a SQL Server table via a custom stored
procedure in the database. All privileges are fine, and the stored
procedure works fine (inserts records perfectly; tested with...
|
by: Michael Wong |
last post by:
Hi,
If I have a stored proc which returns (using RETURN, not an OUT
parameter) a value, how can I get it in a CLI application? Thanks in
advance!
| |
by: cwendell |
last post by:
Hello;
I am a DBA working on a new project with a developer using .NET and C#. I have created a Package (RECORDER_API) with a very simple Procedure in it (add_row). This package is owned by RECORD_OWNER. A synonym has been created for an account RECORD_USER. Execute on RECORDER_API has been granted a role (RECORDING) and this role has been granted to RECORD_USER.
The Procedure add_row has a number of IN parameters but I am having problems...
|
by: jynxxxed |
last post by:
I've been reviewing some of the threads here and applying some of the advice and still getting the same error.
15:50:26,935 INFO java.sql.SQLException: Could not find stored procedure 'getName'.
I'm basically taking a variable coming to my servlet through a JSP page and using it as my search criteria. I know the stored proc will execute through query analyzer, I can execute a regular prepared statement through my servlet, so i know I'm...
|
by: jynxxxed |
last post by:
I've been reviewing some of the threads here and applying some of the advice and still getting the same error.
15:50:26,935 INFO java.sql.SQLException: Could not find stored procedure 'getName'.
I'm basically taking a variable coming to my servlet through a JSP page and using it as my search criteria. I know the stored proc will execute through query analyzer, I can execute a regular prepared statement through my servlet, so i...
|
by: =?Utf-8?B?Vmlua2k=?= |
last post by:
Hello Everyone,
I am trying to call a oracle stored proc from .net code and I am getting
an error
PLS-00306: wrong number or types of arguments in call to KSSP_MEMBER_NEW. I
counted all the number of parameters that I am passing and they seem to be
ok, but type can be the problem. In oracle stored proc , the type is defined
as for example: dayPhone IN MEMBERTable.DayPhone%type
In my ocde I am definig day phone as DbType.string...
|
by: =?Utf-8?B?aUhhdkFRdWVzdGlvbg==?= |
last post by:
I have to retrieve the cloums from the table, but there are few columns in a
table of datatype date and int and the default values are 9999-12-31
23:59:59.997 and -2147483648.
My questions is when I retreive them I sould get value as NOTHING, i mean
blank.
Can any one give me the solution.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |