cancel
Showing results for 
Search instead for 
Did you mean: 

Has anyone used references to Connection Strings?

Michael_Schrote
Champ on-the-rise
Champ on-the-rise

I'm writing scripts that all need to update an external database. Previously (VBScript) this included 1 "INCLUDE" script that only provided the connection details. It seems like that's the way the "Connection Strings" button is supposed to work, but I haven't yet made it be successful. Any sample code or helpful hints would be greatly appreciated.

Thanks in advance!

-Michael S.

1 ACCEPTED ANSWER

Scott_McLean
Elite Collaborator
Elite Collaborator

Hi Michael,

Once you have created a connection string in the Studio, to use it in a Unity script, just do this:

var dbConnection = app.Configuration.GetConnection("name_of_connection");

This will return the generic DbConnection class

If you need to use a specific connection type (for example SqlConnection or OdbcConnection), you can cast it like this:

var sqlConn = (SqlConnection)app.Configuration.GetConnection("name_of_connection");

Hope that helps!

-Scott

View answer in original post

1 REPLY 1

Scott_McLean
Elite Collaborator
Elite Collaborator

Hi Michael,

Once you have created a connection string in the Studio, to use it in a Unity script, just do this:

var dbConnection = app.Configuration.GetConnection("name_of_connection");

This will return the generic DbConnection class

If you need to use a specific connection type (for example SqlConnection or OdbcConnection), you can cast it like this:

var sqlConn = (SqlConnection)app.Configuration.GetConnection("name_of_connection");

Hope that helps!

-Scott