Solved

currentproject.connection vs connection string ms access / sql server

Posted on 2014-10-29
6
228 Views
Last Modified: 2015-01-14
I have a function that was written in DAO against ms access mdb backend that i have converted to sql server backend with linked tables.

I have linked tables.  The function uses transactions which i have already determined to not work with DAO and SQL Server based on experience and research.  So i went about converting to ado.

the transactjon setup was
  Dim NewCheck As New adodb.Recordset
 Set TransTemp = DBEngine.Workspaces(0)
    Set CurDb = TransTemp.Databases(0)
   TransTemp.BeginTrans

i am opening the recordset like this:

      NewCheck.Open sqlstmt, CurrentProject.Connection, adUseClient, adLockBatchOptimistic

 NewCheck.AddNew
       NewCheck![Trans Type] = "Check"
       NewCheck![Account Number] = Account
       NewCheck![Check Number] = NextCheckNum
       NewCheck![Check Date] = Me.Check_Date
       NewCheck![Payee] = ChecksToPay![Supplier Name]
       NewCheck![Supplier Number] = ChecksToPay![Supplier Number]
       NewCheck![Payment Amount] = PmtAmt
       NewCheck![Deposit Amount] = 0
       NewCheck![CurrencyCode] = CurCode
       NewCheck![ExchangeRate] = ExChgRate
       NewCheck![Bill Payment] = True
       NewCheck![Posted] = True
       NewCheck![Memo] = "some memo" ' for SQL Contraint
       NewCheck![Posting GL ID] = "0" ' for SQL Contraint
       NewCheck![Voucher] = "some voucher" ' for SQL Contraint.  this is written later in function


...

 NewCheck.Update
       NewCheck.MoveLast ', NewCheck.LastModified


  TransTemp.CommitTrans


It runs without any error, but does not actually write a new record at all.

Do i need a connection string or will currentproject.connection suffice?  Is the DBEngine.Workspaces(0) workspace even the same workspace as my ado connection??

Press
0
Comment
Question by:pressMac
  • 5
6 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 40412479
I start with
Dim cnn As ADODB.Connection

Then
Set cnn = CurrentProject.Connection

and finally

NewCheck.Open sqlstmt, CurrentProject.Connection, adUseClient, adLockBatchOptimistic

Have you explicitly Dim'd the connection as ado as you have done with the Recordset?


Kelvin
0
 

Author Comment

by:pressMac
ID: 40413095
This looks like you create the cnn object, but then don't use it when opening the recordset.  

NewCheck.Open sqlstmt, cnn, adUseClient, adLockBatchOptimistic.

So i tried it anyway, and then that make another statement break earlier in the code like so:

   ChecksToPay.Open sqlstmt, CurrentProject.Connection

"Run-TIme error '3251', current provider does not support the necessary interface for Index functionality."
0
 

Author Comment

by:pressMac
ID: 40413098
PS:  the ChecksToPay is dim'd this way:
  Dim ChecksToPay As New ADODB.Recordset
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:pressMac
ID: 40416794
in this function some of the recordsets opened are in SQL Server, and others are in a local tmp .mdb file.  So the currentproject.connection points to the frontend file that is open.  So how to i open directly without odbc, the sql table and the tmp table?
0
 

Accepted Solution

by:
pressMac earned 0 total points
ID: 40541632
There were still some DAO recordsets nested in the transaction.  I removed those and then it worked.
0
 

Author Closing Comment

by:pressMac
ID: 40548528
Other answers to not fix problem.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

828 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