This is a migrated thread and some comments may be shown as answers.

DB Connection with in code

3 Answers 214 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Padmashree
Top achievements
Rank 1
Padmashree asked on 06 Jun 2018, 11:09 PM

Hello,

I am testing out SQL Connection with Telerik code . It's simple function to fetch records from SQL server.

Here is code snippet. When I run telerik test with Coded Step ,It's failing on ExecuteReader() statement with error

"Exception thrown executing coded step: 'Tear Down'.
Incorrect syntax near ')'."

Test compiled fine and there is no syntax error on the output.

 

 

 [CodedStep(@"Tear Down")]
        public void DeleteCreatedAcct_TearDown()
        {
            SqlConnection conn ;
            SqlCommand sqlQuery;
            SqlDataReader  sqlDataSet;
            string  sqlQueryString;
           
                       
            conn = new SqlConnection("data source=DBTEST;initial catalog=DBName ;persist security info=True;user id=usrid;password=pwd");
            //Open SQL Connection
            conn.Open();
                      
            Console.WriteLine("DB Name");
            Console.WriteLine(conn.Database);
           
            //Create SQL Command
            sqlQuery = conn.CreateCommand();         
           
            sqlQueryString = "SELECT AcctId FROM DBtable where UpdatedBy ='Automation Tester')";
           
            Console.WriteLine(sqlQueryString);
           
            //Create SQL query to fetch records
            sqlQuery = new SqlCommand(sqlQueryString , conn);
           
            Console.WriteLine("After sqlQuery.CommandText =sqlQueryString" );
            Console.WriteLine("SQL Parameters" + sqlQuery.Parameters);
           
            Console.WriteLine("BEFORE EXECUTE QUERY");
            sqlDataSet = sqlQuery.ExecuteReader();           <<
failing at this line.
            
            Console.WriteLine("After  sqlDataSet = sqlQuery.ExecuteReader();" );            
            while (sqlDataSet.Read())
            {
                Console.WriteLine("Account ID: " + sqlDataSet["AcctId"] );
            }
            
                    
            
        }

Thanks,

-

Padmashree

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Vera
Telerik team
answered on 07 Jun 2018, 02:27 PM
Hello Padmashree,

Thank you for contacting Telerik Support.

I should mention that the provided code snippet from you is a custom one which you could implement and it is not related to Test Studio Framework. I have performed further research on your case and it seems the issue is related to query you use for your database. I have found related resources for you which you may find very useful and will guide you how to resolve the issue. Since we are not familiar with SQL Programming this is the best we could do for you.

Hope this will be helpful for you!

Regards,
Vera
Regards,
Vera
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Padmashree
Top achievements
Rank 1
answered on 07 Jun 2018, 03:33 PM

Thanks Vera.  Issue resolved. 

0
Vera
Telerik team
answered on 08 Jun 2018, 10:22 AM
Hi Padmashree,

Thank you for getting back to us.

We are glad to hear you managed to solve the issue.

If you have further questions do not hesitate to contact us again.

Regards,
Vera
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Padmashree
Top achievements
Rank 1
Answers by
Vera
Telerik team
Padmashree
Top achievements
Rank 1
Share this question
or