DB Connection with in code

4 posts, 1 answers
  1. Padmashree
    Padmashree avatar
    9 posts
    Member since:
    May 2018

    Posted 06 Jun Link to this post

    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

     

     

     

     

     

  2. Answer
    Vera
    Admin
    Vera avatar
    0 posts

    Posted 07 Jun Link to this post

    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!
  3. Padmashree
    Padmashree avatar
    9 posts
    Member since:
    May 2018

    Posted 07 Jun in reply to Vera Link to this post

    Thanks Vera.  Issue resolved. 

  4. Vera
    Admin
    Vera avatar
    0 posts

    Posted 08 Jun Link to this post

    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!
Back to Top