Search code examples
linqpad

Programmatically determine if linqpad script running against production connection string


When I'm running queries in Linqpad I'd like to do some extra checking when the query is being run against a production database, is there a way of detecting programmatically if the connection string that's active for the current linqpad script is marked as production?


Solution

  • Yes, you can get the current connection information using:

     Util.CurrentQuery.GetConnectionInfo()
    

    Which returns an object that contains a IsProduction boolean property, which is True if the connection is marked as such in the connection properties.