Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dr. Watson error while opening a recordset

Posted on 2002-04-07
10
Medium Priority
?
221 Views
Last Modified: 2012-05-04
Well.. here's the problem. I use VBA for some automation purposes. My back-end is SQL Server. I build a query using the user-inputs(like table-name, DSN name etc).

My code runs like this...
Set wrkODBC = CreateWorkspace("", "user", "", dbUseODBC)
Set conDB = wrkODBC.OpenConnection("cnConnect", dbDriverNoPrompt, , "ODBC;DATABASE="+strDatabase+";UID=user;PWD=;DSN=" + strODBCDriver)

Set rs = conDB.OpenRecordset(strQuery, dbOpenSnapshot)

All's well until the last statement. I debugged, and when I pressed F8 on the line Set rs = ..., Dr. Watson error got thrown and Excel closed.

Pls. note that the query that I build in strQuery references the tables - syscolumns and sysobjects - read-only tables for this user.

Any help is appreciated.


======
Shiva.
======
0
Comment
Question by:Shivshankar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6923638
Hi Shivshanskar,

Maybe a simple question but is the DSN available on the machine you try this on?

What you also could try is to set all the parts in the connection string bit by bit instead of openening the connection with a complete string at once

btw is this code from Excel to SQL Server that's not completely clear from this description

:O)Bruintje
0
 
LVL 1

Author Comment

by:Shivshankar
ID: 6924934
burintje,

To answer your questions:
1. Yes, the DSN is available in my system.
2. >>What you also could try is to set all the parts in the connection string bit by bit
  Well, It was like that in the code. But, to make it look short here, I concatenated everything in one-line.
3. Yes, this is a code taken from my EXCEL macro.

Pls. advice.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6927681
Hi Shiva, forgot to ask yesterday what is the precise error message something with -20 etc...?

:O)Bruintje
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Shivshankar
ID: 6931139
 EXCEL.exe
Exception: access violation(0xc0000005), Address:0x44a251d

This is all I get. Any idea ?
0
 
LVL 1

Author Comment

by:Shivshankar
ID: 6955962
I'd also like to mention that this does not happens in all the cases. Excel closes only when I try to open Read-only tables.

Or... lets have it this way. My back-end is sql server. I want to find the columns, their datatype, fieldlength(like sp_help) for a given table. If somebody could give me a solution without using any "sys" tables, I'd appreciate that. If you find that the answer for this question requires more points, kindly let me know.

Thanks.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7118980
Hi Shivshankar, i've no idea

maybe asking for deletion of this question in customer support and asking this question again in VB would give you some more chance of solving it?

:O)Bruintje
0
 
LVL 1

Author Comment

by:Shivshankar
ID: 7119691
bruintje, I do not get this problem when doing the same stuff in VB. It works!!.

It happens only in Excel or Word Macros :-(
0
 
LVL 44

Accepted Solution

by:
bruintje earned 200 total points
ID: 7119733
what about using ado?

place a reference to the ms activex data object into the references list

Dim Con1 As New ADODB.Connection
Dim Cmd1 As New ADODB.Command
Dim RS As New ADODB.Recordset

Con1.Open "DSN=MyDSN;UID=User;PWD=Pwd;"
Cmd1.ActiveConnection = Con1
Cmd1.CommandText = "MyQuery"
RS.CacheSize = 200
RS.Open Cmd1
0
 
LVL 1

Author Comment

by:Shivshankar
ID: 7181780
bruintje,

Sorry for the delay in response. It too did not work. I'm going to forget this problem. Anyway, thanks for all your efforts. I'd like to give you an "A" for that.

Thanks again.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7183191
well thanks sorry to hear it didn't work, but i still wonder why it does work in VB but not in VBA
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question