Forum Discussion

tmahender12's avatar
tmahender12
Frequent Contributor
8 years ago

database connection using testcomplete

i need to connect to database and use the user login and password from db, how can i connect to sql and get data

 

 

thanks

Mahender

  • NisHera's avatar
    NisHera
    Valued Contributor

    This is what you need.

    building connection string could be tricky 

    you can refer this

  • try
          {
                //var excelName = "C:\\TestData.xls"
                var excelFileName = "Test"
                var excelConnection = new Sys.OleObject("ADODB.Connection");
          
                var str_Connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + excelFileName + ";Persist Security Info=False;Extended Properties=Excel 8.0;"
          
                excelConnection.Open(str_Connection);
          
                var excel_recordSet = new Sys.OleObject("ADODB.Recordset");
          
                var excelQuery = select * from login;(example)
          
                excel_recordSet.Open(excelQuery, excelConnection);
          
                if(!excel_recordSet.bof)
                {
                      try
                      {
                            resultValue = aqConvert.VarToStr(excel_recordSet.fields.Item(ColumnName));
                      }
                      catch(e)
                      {     
                            resultValue =  undefined;
                      }
                      
                }
                excel_recordSet.Close();
                excelConnection.Close();