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
I use the following connection string,
"Provider=MSOLEDBSQL19.1; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=<DB Name>; Data Source=<DB Server Name>; Use Encryption for Data=False;"
together with ADO.CreateConnection method.
You can download the appropriate driver from https://learn.microsoft.com/en-us/sql/connect/oledb/applications/installing-oledb-driver-for-sql-server?view=sql-server-ver17 and ensure you can connect to your database using Microsoft SQL Server Management Studio first.