Groups | Blog | Home
all groups > sql server programming > april 2007 >

sql server programming : Outlook 2003 <--> SQL Server 2005


RosH
4/6/2007 10:49:43 PM
I was able to build the following code with the help of some help
topics from Microsoft site for Outlook programming. But unfortunately
errors keep on following me. I have included the code and the error
below. I would appreciate you to comment on it.

My intention is to create a macro in outlook 2003 when triggered at
the definition of a rule in Outlook would read the properties of the
new email and update a SQL Server 2005 database through a database
connection. For example I would like to store and append all the
sender names and the subject field of ruled out emails into a database
which is already defined.

Below is the test for database connection.


Error-----------------
Multiple-Step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done.

Code----------------------

Sub RosHConnectSQL()
Dim Dbcon As New ADODB.Connection
Dim Dbcom As New ADODB.Command
Dim DbRs As New ADODB.Recordset

Dbcon.ConnectionString = "Data Source=.
\SQLEXPRESS;AttachDbFilename=""C:\Documents and Settings\Administrator
\My Documents\Website.mdf"";Integrated Security=True;Connect
Timeout=30;User Instance=True"

Dbcon.Open
Dbcom.ActiveConnection = Dbcon
Dbcom.CommandText = "Select StatusID from Status"
Set DbRs = Dbcom.Execute
MsgBox DbRs(0)

DbRs.Close
Dbcon.Close

End Sub
Erland Sommarskog
4/7/2007 12:00:00 AM
RosH (roshin.majeed@gmail.com) writes:
[quoted text, click to view]

I am puzzled. The error message is a very generic OLE DB error message,
but as I recall it mainly appears when you run queries, and not when you
connect.

In any case, there is an error in your connection string: the
property User Instance is only supported with ADO .Net, and not with
native code, such as ADO Classic. It might be that ADO and OLE DB just
ignores this property, but try removing it and see if things work
out better. I would also recommend that you specify the database with
the Database property, rather than AttachDbFileName.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
RosH
4/7/2007 3:35:33 AM
[quoted text, click to view]

Thank you Erland, I found out the solution,

Dbcon.ConnectionString = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial Catalog=ILA;Data
Source=Server\SQLEXPRESS"

You were right, wrong string = errors.
AddThis Social Bookmark Button