[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ADODB.ActiveConnection error

Posted on 2006-11-08
11
Medium Priority
?
518 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
[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
11 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
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!

 

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

Industry Leaders: 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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

656 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