Solved

ADODB.ActiveConnection error

Posted on 2006-11-08
11
512 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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