Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Im writting a code which enter values in a table1.. But before checking the values in table2 given in the condition.. Only if the condition is correct the values will be entered in table1. Error 3709 appears near cmd.Execute

VB
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Dim BrdSrNo As String
Dim Result As Boolean
Dim machineName As String
Dim stage_Id As String
Dim stage_Status As String
Dim cmd As New ADODB.Command
Dim param As ADODB.Parameter
machineName = Environ("computername")
' Ready objects for use.
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
BrdSrNo = BoardSrNo.Text
Result = False
' Connect.
cn.Open "{Ill give my connection string here}"
' Fetch a recordset.
rs.Open "select * from testreport_tb1 where board_SrNo = '" & BrdSrNo & "' order by test_DateTime desc", cn, adOpenStatic, adLockReadOnly
' Display value, and total recordcount.
MsgBox rs.Fields(3)
MsgBox rs.Fields(8)
'MsgBox rs.RecordCount
stage_Status = rs.Fields(3)
stage_Id = rs.Fields(8)

Set rs = Nothing
Set cn = Nothing

If stage_Status = "True" And stage_Id = "C" Then
MsgBox ("Ok")

     cmd.CommandText = "insert into testreport_tb1 values('" & BrdSrNo & "', 3, GETDATE(), '" & Result & "', NULL, '" & machineName & "', ' KO ', 'A', 'D')"

     Set param = cmd.CreateParameter(BrdSrNo, adVarChar, adParamInput)
     param.Value = BrdSrNo
     param.Size = 25
     cmd.Parameters.Append param
     MsgBox ("Ok")

     Set param = cmd.CreateParameter(Result, adBoolean, adParamInput)
     param.Value = Result
     cmd.Parameters.Append param
     MsgBox ("Ok")

     Set param = cmd.CreateParameter(machineName, adVarChar, adParamInput)
     param.Value = machineName
     param.Size = 10
     cmd.Parameters.Append param
     MsgBox ("Ok")
   
     cmd.ActiveConnection = cn
     cmd.Execute

  MsgBox "saved"
End If
End Sub


What I have tried:

tried opening and closing Cn.open cn.close
Posted
Updated 9-Feb-16 20:22pm
v2
Comments
Maciej Los 10-Feb-16 4:17am    
Error 3709 points to the connection string issue. Please, see: ADO Error Reference[^]
What's database? What connection string are you using?
ZurdoDev 10-Feb-16 7:45am    
You need to provide the error text as well. In fact, as Maciej pointed out, it will tell you exactly what the issue is.
Richard Deeming 10-Feb-16 8:22am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Ivan_FM 13-Feb-16 5:48am    
Thanks! it's a good point about SQL injection.
Ivan_FM 13-Feb-16 5:53am    
Yes, sure it was a connection issue.

Until you provide the full error message, check it out too ;)
Runtime Error 3709 while accesing SQL database in VB6 - Stack Overflow[^]

1 solution

This is a problem with your connection. The full error message, as we've been pointing out, will tell you what is wrong with the connection.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900