473,614 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a SQL Server Stored Proc that contains a CREATE TABLE

3 New Member
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?
Nov 12 '13 #1
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?
Nov 12 '13 #2
pmurch
3 New Member
@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?
---------------------
Expand|Select|Wrap|Line Numbers
  1. cnnConnect.Open "Provider=SQLOLEDB.1;Initial Catalog=" & dbnShort _
  2.             & ";Data Source=myservername;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;" _
  3.             & "Use Encryption for Data=False;Tag with column collation when possible=False;" _
  4.             & "User ID=myuserid;Password=mypassword;"
  5.  
  6.         Set rstRecordset = New ADODB.Recordset
  7.  
  8.         rstRecordset.Open _
  9.             Source:="exec DB_GLOBAL.dbo.[USR_Cred2_DisplayUncompletedCreds-Excel] '" _
  10.                         & dbnShort & "', '" & DBList(idxDB, 2) & "'", _
  11.             ActiveConnection:=cnnConnect, _
  12.             CursorType:=adOpenDynamic, _
  13.             LockType:=adLockReadOnly, _
  14.             Options:=adCmdText
  15.  
  16.         'Add the new QueryTable to the new worksheet and populate it from rstRecordset
  17.         With ActiveSheet.QueryTables.Add( _
  18.             Connection:=rstRecordset, _
  19.             Destination:=Range(wsName & "!A6"))
  20.  
  21.             .Name = "BLSQL1_" & wsName
  22.             .FieldNames = True
  23.             .RowNumbers = False
  24.             .FillAdjacentFormulas = False
  25.             .PreserveFormatting = True
  26.             .RefreshOnFileOpen = False
  27.             .BackgroundQuery = False
  28.             .RefreshStyle = xlInsertEntireRows
  29.             .SavePassword = True
  30.             .SaveData = True
  31.             .AdjustColumnWidth = True
  32.             .RefreshPeriod = 0
  33.             .PreserveColumnInfo = True
  34.             .Refresh (False)
  35.         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:
-----------------
Expand|Select|Wrap|Line Numbers
  1. SET @cmdlogs = 'USE ' + @db + ' '
  2.     + 'IF OBJECT_ID(''USR_LN_UPDATE_BEFORE'') is null '
  3.         + 'BEGIN '
  4.         + 'CREATE TABLE [dbo].[USR_LN_UPDATE_BEFORE]('
  5.         + '[rundate] [datetime] NOT NULL,'
  6.         + '[db] [varchar](40) NOT NULL,'
  7.         + '[mcid] [varchar](12) NOT NULL,'
  8.         + '[CusAddrID] [numeric](12, 0) NOT NULL,'
  9.         + '[Cred] [varchar](100) NULL,'
  10.         + '[Creds] [varchar](40) NULL,'
  11.         + '[Creds Desc] [varchar](40) NULL,'
  12.         + '[Cust LN] [varchar](80) NULL,'
  13.         + '[Cad LN] [varchar](80) NULL,'
  14.         + '[Fmt Dtl] [varchar](400) NULL,'
  15.         + '[Srch Name] [varchar](80) NULL,'
  16.         + '[Script Name] [varchar](255) NULL) '
  17.         + 'GRANT ALTER ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
  18.         + 'GRANT DELETE ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
  19.         + 'GRANT INSERT ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
  20.         + 'GRANT SELECT ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
  21.         + 'GRANT UPDATE ON [dbo].USR_LN_UPDATE_BEFORE TO xlsuser '
  22.         + 'END '
  23.     + 'IF OBJECT_ID(''USR_LN_UPDATE_AFTER'') is null '
  24.         + 'BEGIN '
  25.         + 'CREATE TABLE [dbo].[USR_LN_UPDATE_AFTER]('
  26.         + '[rundate] [datetime] NOT NULL,'
  27.         + '[db] [varchar](40) NOT NULL,'
  28.         + '[mcid] [varchar](12) NOT NULL,'
  29.         + '[CusAddrID] [numeric](12, 0) NOT NULL,'
  30.         + '[Cred] [varchar](100) NULL,'
  31.         + '[Creds] [varchar](40) NULL,'
  32.         + '[Creds Desc] [varchar](40) NULL,'
  33.         + '[Cust LN] [varchar](80) NULL,'
  34.         + '[Cad LN] [varchar](80) NULL,'
  35.         + '[Fmt Dtl] [varchar](400) NULL,'
  36.         + '[Srch Name] [varchar](80) NULL,'
  37.         + '[Script Name] [varchar](255) NULL) '
  38.         + 'GRANT ALTER ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
  39.         + 'GRANT DELETE ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
  40.         + 'GRANT INSERT ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
  41.         + 'GRANT SELECT ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
  42.         + 'GRANT UPDATE ON [dbo].USR_LN_UPDATE_AFTER TO xlsuser '
  43.         + '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?
Nov 12 '13 #3
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.
Nov 12 '13 #4
pmurch
3 New Member
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!
Nov 13 '13 #5
Rabbit
12,516 Recognized Expert Moderator MVP
No problem, glad you got it working!
Nov 13 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4299
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.
2
1661
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...
1
1979
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
3
1468
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...
1
1258
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!
1
1232
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...
3
2233
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...
1
4176
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...
3
4120
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...
2
1078
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.
0
8176
marktang
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...
0
8120
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,...
1
8265
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,...
0
8423
tracyyun
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...
1
6085
isladogs
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...
0
5537
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();...
0
4115
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2560
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
1
1705
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.