Page 1 of 1

Connecting Ranorex to SQL server 2008

Posted: Mon Apr 16, 2012 10:21 am
by rohitjain3333
Hi,
Please tell me how to connect ranorex withSQL server 2008.
I am trying following code but gives me error.
Please help!!

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
"Driver={SQL Server};" +
"Server=ServerName;" +
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();

Re: Connecting Ranorex to SQL server 2008

Posted: Mon Apr 16, 2012 2:50 pm
by slavikf
Here is my code:
public static string RexConnection = "Data Source=REX;" +
                                       "user=mvois;password=" + Common.MVPass +
                                       ";database=AutoRex";

		public static void ValidateSQL (string TC, string query, string field, string expected)
 {
			Report.Info ("Attemting to connect with: " + Common.RexConnection);
        	SqlConnection myConnection;
			myConnection = new SqlConnection(Common.RexConnection);			
			try	{
				myConnection.Open();
				SqlCommand    myCommand = new SqlCommand(query, myConnection);
    			SqlDataReader myReader = myCommand.ExecuteReader();
    			if (myReader.Read()) {
    				string Actual = myReader[field].ToString();
    				if (Actual.Equals (expected))
    					Report.Success (TC + ": Actual value of " + field + ": " + Actual);
    				else
    					Report.Failure (TC + ": Actual value of " + field + ": " + Actual +". Expected: "+ expected);
    			}
    			myConnection.Close();
			}
			catch(Exception e)
			{
    			Report.Warn (TC + ": DB access error: " + e.ToString());
			}
		}
Check following link to see all details of Connection string:

http://msdn.microsoft.com/en-us/library ... tring.aspx

Re: Connecting Ranorex to SQL server 2008

Posted: Mon Apr 16, 2012 4:17 pm
by omayer
thank your for your reply, i am trying to connect to sqlserver2008 and query data in table then use it as parameter, thank you again