MCPcopy Create free account
hub / github.com/Azure/sql-action / tryConnection

Method tryConnection

src/SqlUtils.ts:54–86  ·  view source on GitHub ↗

* Tries connection with the specified configuration. * @param config Configuration for the connection. * @param useMaster If true, uses "master" instead of the database specified in @param config. Every other config remains the same. * @returns A ConnectionResult object indicating suc

(config: SqlConnectionConfig, useMaster?: boolean)

Source from the content-addressed store, hash-verified

52 * @returns A ConnectionResult object indicating success/failure, the connection on success, or the error on failure.
53 */
54 private static async tryConnection(config: SqlConnectionConfig, useMaster?: boolean): Promise<ConnectionResult> {
55 const database = useMaster ? "master" : config.Database;
56
57 let sqlCmdError = '';
58 try {
59 core.debug(`Validating if client has access to '${database}' on '${config.Server}'.`);
60 let sqlCmdCall = this.buildSqlCmdCallWithConnectionInfo(config, database);
61 sqlCmdCall += ` -Q "SELECT 'Validating connection from GitHub SQL Action'"`;
62 await exec.exec(sqlCmdCall, [], {
63 silent: true,
64 listeners: {
65 stderr: (data: Buffer) => sqlCmdError += data.toString(),
66 // Some AAD errors come through as regular stdout. For this scenario, we will just append any stdout
67 // to the error string since it will only be surfaced if sqlcmd actually fails.
68 stdout: (data: Buffer) => sqlCmdError += data.toString()
69 }
70 });
71
72 // If we reached here it means connection succeeded
73 return {
74 success: true
75 };
76 }
77 catch (error) {
78 core.debug(`${error.message}`);
79 core.debug(`SqlCmd stderr: ${sqlCmdError}`);
80 return {
81 success: false,
82 errorMessage: sqlCmdError,
83 ipAddress: this.parseErrorForIpAddress(sqlCmdError)
84 };
85 }
86 }
87
88 /**
89 * Parse an error message to see if it contains an IP address.

Callers 1

detectIPAddressMethod · 0.95

Calls 5

debugMethod · 0.80
execMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected