Connecting Ranorex to SQL server 2008 : Automation API

Connecting Ranorex to SQL server 2008

Class library usage, coding and language questions.

Connecting Ranorex to SQL server 2008

Postby rohitjain3333 » Mon Apr 16, 2012 11: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();
rohitjain3333
 
Posts: 20
Joined: Tue Sep 20, 2011 8:12 am

Re: Connecting Ranorex to SQL server 2008

Postby slavikf » Mon Apr 16, 2012 3: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
User avatar
slavikf
 
Posts: 102
Joined: Mon Sep 13, 2010 10:07 pm
Location: Toronto, Canada

Re: Connecting Ranorex to SQL server 2008

Postby omayer » Mon Apr 16, 2012 5: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
omayer
 
Posts: 427
Joined: Thu Oct 28, 2010 7:14 pm


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests