Use Credential Manager to host SQL authentication

Hi,

Now InTouch embedd credential manger.

It is possible to store a SQL Login/Pwd and reuse it to connect to a SQL database through scripting ?

I'm not speaking about connecting an user or passing SQL to AlarmClient/Trend.

The goal is to execute a SQL query without using clear text password.

Thanks

Parents Reply Children
  • Here is an example to start with, but as mentioned earlier, if your query takes time to finalize, then you need to start manage the connection Async, (let the script poll for completion and capture the result once it is completed) and don't forget your Command.Dispose(); !

    doing so will generate a memory leak over time.

    dim Connection 	as aaDBClient.aaDBConnection;
    dim Command    	as aaDBClient.aaDBCommand;
    'dim Transaction as aaDBClient.aaDBTransaction;
    'Create a connection object with the connection string.
    LogMessage("Creating connection");
    'Connection = aaDBAccess.CreateConnection("Data Source=localhost;Initial Catalog=AdventureWorks;Integrated Security=true");
    Connection = aaDBAccess.GetConnection("server=localhost;database=LABDB;Trusted_Connection=yes", aaDBConnectionType.Sql);
    'Create a command object for the transaction object, with a SQL statement or Stored Procedure.
    LogMessage("Creating a command object");
    'Command = Connection.CreateCommand("Select Column1 from ...", aaDBCommandType.SqlStatement, TRUE);
    Command = Connection.CreateCommand("GetData", aaDBCommandType.StoredProcedure, TRUE);
    Command.SetIntParameterByName("@wait", QueryTime, 	aaDBParameterDirection.Input);
    Command.SetIntParameterByName("@rc", RowCount, 	aaDBParameterDirection.Input);
    Command.SetBitParameterByName("@DoError", DOError, 	aaDBParameterDirection.Input);
    
    'Everything is ready, let's execute the transaction sync.
    LogMessage("Executing transaction sync");
    dim ResultCode as integer;
    ResultCode = Command.ExecuteSync();
    If ResultCode <> 0 Then  
    	'Failed to execute transaction sync, report the reason.
    	LogMessage("Got error " + ResultCode + " executing transaction sync");
    Else
    	If Command.ExecutionState == aaDBTransactionState.Failed Then
    			Catcherror = Command.LastExecutionError;
    			LogWarning("Execution error: "+Command.LastExecutionError);
    			'Possibility to retry or manage error here
    	elseif Command.ExecutionState == aaDBTransactionState.Completed Then
    		dim Rows as integer;
    		Rows = Command.RowCount;
    		LogMessage("Row count returned from command is " + Rows);
    		'Use other methods of script library to read data and assign to UDAs, etc.
    		if Rows > 0 then
    			'Manage result from query, (single row)
    			dim Column1 as string; 
    			Column1 = Command.GetCurrentRowColumnByName("Column1"); 
    			LogMessage("Got data "+Column1);
    			Sync_Column1 = Column1;
    		endif;
    		if Rows > 0 then
    			'Manage result from query, (loop rows), 
    			'in this case the SP returns two datasets, and the second one (1) has to be selected
    			Command.SelectTable(1);
    			'dim dt as System.Data.DataTable;
    			'DataGridView1.Datasource = Command.GetDataset().Tables(1);
    			LogMessage("rows found: "+Command.RowCount());
    			dim j as integer;
    			for j = 0 to Command.RowCount-1
    				Command.SelectRow(j);
    				ComboBox1.AddItem(Command.GetCurrentRowColumnByName("Rows"));
    			next;
    		endif;
    	EndIf;
    EndIf;
    
    Command.Dispose();
    
    Sync_GetData = false;

  • Thanks a lot ! I would like to see as a feature the Credentials Manager be able to use for scripting such as web browser authentication. Also Richard, I'm planning to create an Intouch backup where I would implement a Gold Class Standard of everything ( graphics, scripting, efficient methods ) from an old Intouch project upgrade. Would you by any chance have a public project that I can use in Intouch ?