473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

dbConnection.Execute fails after I installed sql 2008

ck9663
2,878 Expert 2GB
Hi guys,

I have this code working when my local machine only have SQL2005. There is a need for me to install SQL2008, so I did. I now have two versions of SQLServer and now it's not working.

This is a VBA Script in my OUTLOOK that reads my incoming email, parse the subject and execute a stored procedure to another server, not my (local) server.

Could you guys help me out on this

Expand|Select|Wrap|Line Numbers
  1. Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
  2.    Dim arr() As String
  3.    Dim sqlStr As String
  4.    Dim i As Integer
  5.    Dim ns As Outlook.NameSpace
  6.    Dim itm As MailItem
  7.    Dim m As Outlook.MailItem
  8.    Dim dbConn As ADODB.Connection
  9.    Set dbConn = New ADODB.Connection
  10.    Dim rs As Recordset
  11.  
  12.    dbConn.ConnectionString = "DRIVER={SQL Server};SERVER=(local);DATABASE=Compositions;UID=;PWD=;"
  13.  
  14.    dbConn.Open
  15.  
  16.    Set ns = Application.Session
  17.    arr = Split(EntryIDCollection, ",")
  18.    For i = 0 To UBound(arr)
  19.       Set itm = ns.GetItemFromID(arr(i))
  20.       If itm.Class = olMail And Trim(itm.SenderName) = "ThisSender" And Trim(itm.SenderEmailAddress) = "thisemail@address" Then
  21.  
  22.          sqlStr = "declare @sqlstatement varchar(max) "
  23.          sqlStr = sqlStr & " set @sqlstatement = 'exec StoredProcName ''" & Mid(itm.Subject, 32, 3) & "'', ''" & Mid(itm.Subject, 36, 3) & "'''"
  24.  
  25.          sqlStr = sqlStr & " exec (@sqlstatement) at [LinkedServerNameHere]"
  26.  
  27.          Set rs = dbConn.Execute(sqlStr)
  28.  
  29.          dbConn.Close
  30.  
  31.          Set dbConn = Nothing
  32.          Set rs = Nothing
  33.  
  34.       End If
  35.    Next
  36.    Set ns = Nothing
  37.    Set itm = Nothing
  38.    Set m = Nothing
  39. End Sub
  40.  
The dbConn.State = 1 which means I am connected. But the record state = 0.

Any idea?

Thanks,

~~ CK
Jun 13 '11 #1

✓ answered by NeoPa

Hi CK.

Can you say if/where it crashes and any error messages you see?

My first tip, before we get going properly, is to ensure that all variables of types which have DAO and ADODB flavours, should be defined explicitly as such. I expect you would want (in line #10) :
Expand|Select|Wrap|Line Numbers
  1. Dim rs As ADODB.Recordset

5 2753
NeoPa
32,556 Expert Mod 16PB
Hi CK.

Can you say if/where it crashes and any error messages you see?

My first tip, before we get going properly, is to ensure that all variables of types which have DAO and ADODB flavours, should be defined explicitly as such. I expect you would want (in line #10) :
Expand|Select|Wrap|Line Numbers
  1. Dim rs As ADODB.Recordset
Jun 13 '11 #2
ck9663
2,878 Expert 2GB
Thanks NeoPa.

It's really strange. This code does not return anything and seems to be not working:

Expand|Select|Wrap|Line Numbers
  1. Set rs = dbConn.Execute(" declare @x as int; set @x = 1; select @x as x")
  2.  
But this works:
Expand|Select|Wrap|Line Numbers
  1. Set rs = dbConn.Execute(" declare @x as int; select @x as x")
  2.  
Any idea?
Jun 14 '11 #3
NeoPa
32,556 Expert Mod 16PB
Particularly strange as it appears to be T-SQL relative CK :-S

I'm afraid I can't help there much as I've lost all my SQL servers now and have nothing to test on. Do I remember though that there is an alternative command for SET in T-SQL. I thought it was sometimes replaceable with SELECT. I have to admit my recollection is pretty fuzzy though. My T-SQL was always heavily dependent on the Books Online help system. I'm afraid I did far too little of it in my job to get familiar with much of it :-(
Jun 15 '11 #4
ck9663
2,878 Expert 2GB
Thanks Neo. Yes you are right, as an assignment statement, SET can always replace SELECT, but not the other way around.

The T-SQL is running fine if I paste it in the server. It is also the same connection technique am using in a Classic ASP application and it's running fine. So it really puzzles me.

Anyway, thanks for the help. I'll try to figure this out :)


~~ CK
Jun 15 '11 #5
NeoPa
32,556 Expert Mod 16PB
I'm sorry I couldn't be more help CK. I remember you often helped me when I needed SQL Server help.
Jun 15 '11 #6

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

Similar topics

1
by: Phil Powell | last post by:
Here is the scope of what I need to do; want: enrollment_year allowed (even if null) all of ica criteria:
0
by: R. Sterrenburg | last post by:
Hi, I have a Server.Execute("MyStaticHTML.html") in the codebehind of a UserControl. When I put this UserControl on a page MyPage.aspx it correctly puts the content of the MyStaticHTML.html in...
2
by: Ryan Taylor | last post by:
Hello. I have an ASP.NET web application in which one page needs to execute another page and retrieve it's results. The page to be called needs a couple parameters passed in the URL. However,...
7
by: deltalimagolf | last post by:
I now get the following error message after copying an asp.net application to the deployment web server. I don't have SQLExpress or any version of SQL 2005 installed. I found the "LocalSQLServer"...
8
by: VB Programmer | last post by:
I would appreciate your assistance on this ASP.NET 2.0 site.... This is the wierd problem: While accessing the built in .NET functions for 'profiling' or 'membership' an error is generated (see...
0
by: kkos | last post by:
I noticed the following issue posted as a double-hop issue in many discussion boards but found no answers that explain how to pass the second hop with windows auth from IIS ASPX page to remote SQL...
0
by: =?Utf-8?B?TWlyYW5v?= | last post by:
I tried it several times, setup disk is not damaged, everything is fine, but it always fails with the error below after completing like 75% of the installation. Then I saw other posts, and figured...
0
by: CheshireCat | last post by:
Hi, I've just installed 2008 on my home pc and am trying to open a project, stored in sourcesafe, across the internet. Ive enabled the sourcesafe internet plug in. In VS2005, I would select to...
1
by: ErikJL | last post by:
I have a simple webservice that performs a SELECT query against a database, and then an INSERT statement on the same database/table. The problem arises at the time when we create the second OleDB...
3
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've created a class that wraps DbConnection. public class CSQL { protected System.Data.Common.DbConnection m_conn; public CSQL {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.