lprun -compileonly connects to databases specified in Connection element

edited September 19
I don't think lprun should be attempting to connect to databases specified in the <Connection> element of the file when -compileonly is specified.

I'm trying to verify that linqpad scripts are not broken by code changes during an automated build, but it fails if the connection string is not pointing at a running database instance.

I'm using 5.26.01

Comments

  • UserQuery is derived from the TypedDataContext class, therefore the data context must be created before the actual query can be compiled.
  • While that's great technical detail as to why it's currently happening, I still don't think it should be happening.
  • I could allow a cached datacontext to be used without checking whether the schema is stale. I will look into this in the next build. However, if there's no cached data context on that machine, it will be impossible, because as nescafe says, it cannot compile a query if the base class cannot be generated.
  • edited September 24
    What's the difference between a normal query and a query with a connection string specified? Normal queries, which do not have a connection string, compile without issue, but as soon as a connection string is added, it needs to be pointing at a running instance or the query will not compile.

    We're only using the connection string as a convenient way for different people to run the same script with their own connection string, without having to save it somewhere else and copy and paste it into every script they want to run. We aren't using any ORM type entity mapping, etc. because all of our data access goes through our own libraries, they just need to be provided a connection string as configuration. We really just want to ensure that changes to our own libraries won't break our own scripts.

    If Connection.ConnectionString compiled, but had a null value, that would be enough for us. If this was hidden behind a command line argument to lprun so as not to cause breaking changes, that would also be fine.
  • So you're using the connection only as a placeholder, to be re-selected at runtime? Then you could store the LINQPad script without a connection and read the connection string via reflection.
    var connection = this.GetType().GetProperty("Connection")?.GetValue(this);
    if (connection == null)
    {
      throw new Exception("Please select a connection.");
    }
    var connectionString = connection.GetType().GetProperty("ConnectionString")?.GetValue(connection);
    
    connectionString.Dump();
    Another option would be to store the connection string per computer using Util.SaveString() method:
    // Run once on every computer:
    // Util.SaveString("connStr", "Data Source=(local)");
    
    using (var ctx = new DataContextBase(Util.LoadString("connStr") ?? "Data Source=(local)"))
    {
      ctx.ExecuteQueryDynamic("SELECT * FROM sys.tables").Dump();
    }
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!