Page 1 of 1

"CommandText property has not been initialized" error

Posted: Wed Apr 06, 2016 5:47 pm
by vivek.guvva
Hi, I am passing sql query as a parameter to the function. When i try to execute the code, it is throwing me error "ExecuteReader: CommandText property has not been initialized"

It works fine when i put SQl query in the code and execute. The problem is when I am passing that query as parameter using excel data connector. Below is the code that i have used. Please let me know where might be the issue.


Public Shared Sub TestConnection(query as String)

Dim digitalTracksDT As System.Data.DataTable
Dim conn As New OdbcConnection("DSN=Database_Name")
conn.Open()
System.Console.WriteLine("Database Connection opened ")
Dim digitalTrackGet As New OdbcCommand(query, conn)
Dim adp3 As New OdbcDataAdapter(digitalTrackGet)
adp3.Fill(digitalTracksDT)
System.Console.WriteLine("Data Table filled successfully")

conn.Close()

End Sub

Re: "CommandText property has not been initialized" error

Posted: Thu Apr 07, 2016 7:46 am
by odklizec
Hi,

Is this problem somehow related to another your post?...
http://www.ranorex.com/forum/pass-param ... t9236.html
Have you debugged the code? Is the 'query' variable actually filled with something?

Re: "CommandText property has not been initialized" error

Posted: Thu Apr 07, 2016 12:55 pm
by vivek.guvva
Hi,
I think this another issue when code is executed from recorder. I am getting this error when I am executing the code module from recorder even thought the parameter values are defined in the code itself.

Re: "CommandText property has not been initialized" error

Posted: Fri Apr 08, 2016 1:24 pm
by RobinHood42
Hi,

take a look at the following thread:

https://social.msdn.microsoft.com/Forum ... aproviders

I aggree totally with Pavel, you should use the debugger in order to analyze your code.

Cheers,
Robin