Forum Discussion

hina's avatar
hina
Contributor
3 months ago
Solved

Connection string using managed identity authentication

Hi,

I am trying to connect to the Azure SQL database using managed identity. Here is my the code:

AConnection = ADO.CreateADOConnection();

// Specify the connection string
var AConnection = ADO.CreateADOConnection();
                 

AConnection.ConnectionString = "Provider=sqloledb;Trusted_Connection=Yes;Data Source=<server_name>;Initial Catalog=<db name>;Authentication=Active Directory Managed Identity;";

// Suppress the login dialog box    
AConnection.LoginPrompt = false;    
AConnection.Open();

// Execute a query to see if the table is accessible
RecSet = AConnection.Execute_("SELECT * FROM <table_name>");

// Iterate through query results and insert data into the test log    
RecSet.MoveFirst();

while(! RecSet.EOF)    
{    
    Log.Message(RecSet.Fields.Item("<column_name>").Value); 
      
    RecSet.MoveNext();
}    
AConnection.Close();
}

When I add Authentication=Active Directory Managed Identity; in connection string, TestComplete gives me an error: "Invalid connection string attribute".

My question is how would I specify in the connection string that the authentication type is managed identity. Right now I am not able to connect to the database.

Thanks,

Hina

4 Replies