[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ADODB.ActiveConnection error

Posted on 2006-11-08
11
Medium Priority
?
520 Views
Last Modified: 2008-01-09
In Access 2003 VBA, I'm trying to code the deleting of a record using an adodb connection.
I have this ccode:

Global Const sconnecttest = "ODBC;DRIVER=SQL Server;SERVER=Pauljmcneil;APP=Microsoft Office 2003;" _
  & "WSID=PAULJMCNEIL;DATABASE=jjtptab13SQL;Trusted_Connection=Yes"

Dim cmd As New ADODB.Command
Dim cnn As New ADODB.Connection
 
  sql = "DELETE FROM dbo.tblCustomer WHERE dbo.tblCustomer.CustomerID=23283"
  Set cmd = New ADODB.Command
  cnn.ConnectionString = sconnecttest & ";TABLE=dbo.tblCustomer"
  cmd.ActiveConnection = cnn.ConnectionString
  cmd.CommandText = sql
  cmd.CommandType = adCmdText
  cmd.Execute

I get the following error on the line:
cmd.ActiveConnection = cnn.ConnectionString

"Data source name not found and no default driver specified"
Thanks
0
Comment
Question by:paulmcneil
10 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17901812
>  cnn.ConnectionString = sconnecttest & ";TABLE=dbo.tblCustomer"
The ADODB.Connection object is used to connect to a database, not a table, so lose the above line
0
 

Author Comment

by:paulmcneil
ID: 17901869
jimhorn,
Removing the ";TABLE=dbo.tblCustomer" from the connect string does not eliminate the error
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 17901937
Try this:  

sql = "DELETE FROM dbo.tblCustomer WHERE dbo.tblCustomer.CustomerID=23283"
  Set cmd = New ADODB.Command
  cnn.ConnectionString = sconnecttest
  cmd.ActiveConnection = cnn
  cmd.CommandText = sql
  cmd.CommandType = adCmdText
  cmd.Execute

AW
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 

Author Comment

by:paulmcneil
ID: 17902007
Arthur Wood,
You suggested change raises the error: "Requested operation requires an OLE DB Session object, which is not supported by the current provider"
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 17902504
ok, then you should do it this way:

sql = "DELETE FROM dbo.tblCustomer WHERE CustomerID=23283"
cnn.ConnectionString = sconnecttest
cnn.Execute sql

AW
0
 

Author Comment

by:paulmcneil
ID: 17903686
AW
With the code you suggested I get the error: "Operation is not allowed when the object is closed."
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 17904037
sql = "DELETE FROM dbo.tblCustomer WHERE CustomerID=23283"
cnn.ConnectionString = sconnecttest
cnn.Open
cnn.Execute sql

0
 

Author Comment

by:paulmcneil
ID: 17906172
AW
That sequence of code raises the error:"Data source name not found and no default driver specified"
Again, the constant sconnecttest is set with:
Global Const sconnecttest = "ODBC;DRIVER=SQL Server;SERVER=Pauljmcneil;APP=Microsoft Office 2003;" _
  & "WSID=PAULJMCNEIL;DATABASE=jjtptab13SQL;Trusted_Connection=Yes"
0
 

Author Comment

by:paulmcneil
ID: 17906588
AW
The following code worked for deleting a single record with an ADO connection:


''''''''''''''''''''''''''''''''''''''''''
'Example of ADO code for deleting a record
''''''''''''''''''''''''''''''''''''''''''

Dim scnn As String
Dim ssql As String
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

scnn = "DSN=jjtpsqlmcneil;Server=pauljmcneil;Database=jjtptab13SQL;Trusted_Connection = Yes;"
ssql = "SELECT  dbo.tblCustomer.* FROM dbo.tblCustomer WHERE dbo.tblCustomer.CustomerID=23283"
Set cnn = New ADODB.Connection
cnn.ConnectionString = scnn
cnn.Open
rs.Open sql, cnn, adOpenDynamic, adLockOptimistic
With rs
  .Delete
End With
 
''''''''''''''''''''''''''''''''''''''''''
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18320548
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

826 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