Data Validation in database

Ranorex Spy, Recorder, and Studio.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Data Validation in database

Post by omayer » Wed Jan 23, 2013 3:39 pm

What am i missing on this code, can't pass ther error, --No parameterless constructor defined for this object.
Thank you in Advance



Show/Hide Stacktrace
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at Ranorex.Core.Testing.TestModuleActivator.DefaultFactoryMethod.CreateFactory() at Ranorex.Core.Testing.TestSuiteModule.InitializeTestModuleInstance() at Ranorex.Core.Testing.TestSuiteModule.RunWithRepeats(DataContext parentDataContext, ErrorBehavior errorBehavior) at Ranorex.Core.Testing.TestSuiteModule.Run(DataContext parentDataContext, Boolean childSkip)

"
code is used

Code: Select all

 public class MSSQLConnector : ITestModule
    {
    	
    	private string server, database, uid, password, connectionString;

        	//construct	
        public MSSQLConnector(string _server, string _database, string _username, string _password)
        {
         	this.server = _server;
			this.database = _database;
			this.uid = _username;
			this.password = _password;
			this.connectionString = "user id="+this.uid+";"+"password="+this.password+";"[email protected]"server="+this.server+";"+"database="+this.database+";"+"connection timeout=30";

        	
        }


		public DataTable RunQuery(string SQL)
		{

			SqlConnection connection = new SqlConnection(connectionString);
			SqlDataReader reader = null;
			DataTable dt = new DataTable();
			try{
				SqlCommand command = connection.CreateCommand();
				command.CommandText = SQL;
				connection.Open();
				reader = command.ExecuteReader();
				dt.Load(reader);
				}
			catch(Exception e){
				Console.WriteLine("Exception is MSSQLConnector::RunQuery – " + e.ToString());
				}
			finally{
				reader.Close();
				connection.Close();
				}
				return dt;
		}
  void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;            
      //connector object
     MSSQLConnector db = new MSSQLConnector("NQ08\\NQ08", "QA", "generic", "password");
		
		
			//validate middle name 			
DataTable dt= db.RunQuery("Select * from candidate where firstname='Sam'");
			foreach(DataRow row in dt.Rows)
			{
				Ranorex.Validate.IsTrue(row["middlename"].ToString() == "S", "Validating Sam middle name S.");


		}
    }
}
}
Tipu

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Data Validation in database

Post by Support Team » Thu Jan 24, 2013 2:33 pm

Hi,

This is because if you execute the specific CodeModule "MSSQLConnector" in Ranorex, Ranorex internally calls the standard constructor of the CodeModule in order to run it and as there is no such constructor Ranorex throws the mentioned error.
In order to fix this you have to define the standard constructor:
public MSSQLConnector(){
			
		}
or, I would prefer this solution, you could create a normal, a not runnable class (C# Class template), for your SQLConnector.
This SQLConnector class can then be called from your UserCodeModule or your UserCode method of a Recording.

Regards,
Markus
.
Image

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

Re: Data Validation in database

Post by omayer » Thu Jan 24, 2013 4:41 pm

Thank you Markus for the expalanantion and solution, I will go with C# Class template
Tipu

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Data Validation in database

Post by Support Team » Thu Jan 24, 2013 5:31 pm

You're welcome!

This is a good choice ;).

Regards,
Markus
.
Image