Connecting Ranorex to SQL server 2008

Class library usage, coding and language questions.
rohitjain3333
Posts: 20
Joined: Tue Sep 20, 2011 7:12 am

Connecting Ranorex to SQL server 2008

Post by rohitjain3333 » Mon Apr 16, 2012 10:21 am

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();

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: Connecting Ranorex to SQL server 2008

Post by slavikf » Mon Apr 16, 2012 2:50 pm

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

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Connecting Ranorex to SQL server 2008

Post by omayer » Mon Apr 16, 2012 4:17 pm

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
Tipu