How to use credentials from assets to connect to Database?

How to use credentials from assets to connect to Database?

I have a username and password in my assets as credentials. How can I use that to connect to a SQL server database?

Hi ,
You need to use Get Credential activity to get your username and password from orchestrator.
Then you will concatenate them to pattern of connection string for SQL.

Example Basic connection string
“Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;”

After you have connection string, you can use Connect activity (UiPath.Database.Activities) to connect to SQL database server.
Pic

1 Like

Thank you for your help. I already got my credentials. But the I can’t create the connection string from my password. The password is a different type it is a secure string. Is there a way to connect to a SQL server using the secure string password?

Hi,
You can convert secure string to string (using Assign activity), please see example below. ( change mySecurePassword to your secure string variable )

String strpwd = new System.Net.NetworkCredential(string.Empty, mySecurePassword).Password

1 Like

Hi travineei, once again I appreciate your help. The reason I did not do that already is because I heard turning the password into a simple string will create security issues. Is there another way or is this the only way to do it?

Hi,
The connection string must be in String type. I think the best for this part is to put converter in line of connection string like this >>

“Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password="+ new System.Net.NetworkCredential(string.Empty, mySecurePassword ).Password+ ";”

1 Like

It is not perfect since you can use wireshark to see the connection string. But it looks like this is the only way. Thank so much.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.