bbsimonbb/query-first

query.gen.cs empty

Closed this issue · 11 comments

Installed the vsix, created the QfDefaultConnection and QfRuntimeConnection in the settings, created the QfRuntimeConnection.GetConnection method to return a SqlConnection from the QfRuntimeConnection setting.

Created a new .sql from the template, attached to a database, created and tested a query, but on save (and Build/ReBuild) nothing gets generated in the query.gen.cs class, and I get object reference errors in the Output|QueryFirst window:

Object reference not set to an instance of an object. at QueryFirst.CodeGenerationContext..ctor(Document queryDoc) in C:\mydev\QueryFirstV\QueryFirst\CodeGenerationContext.cs:line 36
at QueryFirst.Conductor.ProcessOneQuery(Document queryDoc) in C:\mydev\QueryFirstV\QueryFirst\Conductor.cs:line 30
at QueryFirst.SolutionEventHandlers.myDocumentEvents_DocumentSaved(Document Document) in C:\mydev\QueryFirstV\QueryFirst\SolutionEventHandlers.cs:line 255

Any help appreciated (looked through StackOverflow and the GitHub issues).

Thanks!

sounds like you need a provider name on your connection string. Sql Server? try providerName="System.Data.SqlClient"

Sorry about the cryptic error message.

Thanks for the response!

I do have the provider name in the connection string, and have tried both trusted connection and direct with an sa account:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
    </startup>
  <connectionstrings>
    <add name="QfDefaultConnection" connectionstring="Server=EM-BK-DEV-DATA;Integrated Security=False;Database=EmpireBPM;ID=sa;Password=*********;TrustServerCertificate=True;" providername="System.Data.SqlClient"/>
  </connectionstrings>
  <connectionstrings>
    <add name="QfRuntimeConnection" connectionstring="Server=EM-BK-DEV-DATA;Integrated Security=False;Database=EmpireBPM;ID=sa;Password=**********;TrustServerCertificate=True;" providername="System.Data.SqlClient"/>
  </connectionstrings>
</configuration>

Still getting an error, thought I have gotten slightly farther (it was not clear to me whether to create the method QfRuntimeConnection.GetConnection() or QfRuntimeConnection.GetConnectionString(), and I have tried either, and both, with no joy):

Object reference not set to an instance of an object.   at QueryFirst.CodeGenerationContext..ctor(Document queryDoc) in C:\mydev\QueryFirstV\QueryFirst\CodeGenerationContext.cs:line 36
   at QueryFirst.Conductor.ProcessOneQuery(Document queryDoc) in C:\mydev\QueryFirstV\QueryFirst\Conductor.cs:line 30
   at QueryFirst.QueryFirstCmd.ProcessAllItems(ProjectItems items, VSOutputWindow vsOutputWindow) in C:\mydev\QueryFirstV\QueryFirst\QueryFirstCmd.cs:line 120

Accidentally closed the issue :(

try adding both connection strings to the same connectionStrings group...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
    </startup>
  <connectionStrings>
    <add name="QfDefaultConnection" connectionstring="Server=EM-BK-DEV-DATA;Integrated Security=False;Database=EmpireBPM;ID=sa;Password=*********;TrustServerCertificate=True;" providername="System.Data.SqlClient"/>
    <add name="QfRuntimeConnection" connectionstring="Server=EM-BK-DEV-DATA;Integrated Security=False;Database=EmpireBPM;ID=sa;Password=**********;TrustServerCertificate=True;" providername="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

Starting today, for .net core compatibility, QueryFirst no longer looks in app or web.config. See the readme for up-to-date details. You need to put these parameters in a qfconfig.json, beside or anywhere above the .sql file.

Question about the qfconfig.json file, what is this: "helperAssembly":[pathToDll], - what path (relative or absolute) to what dll? An example please, thanks!

Any of the QueryFirst interfaces can be implemented in a helper dll (ICodeGenerationContext, IConfigFileReader, IConfigResolver, IQueryParamInfo, ISignatureMaker, IWrapperClassMaker). IProvider implementations need a registrationName attribute that matches the provider specified for the query. Implementations in the helper dll will have precedence over my own implementations. The pathToDll should be an absolute path.

The most obvious use of this would be an implemenation of IProvider to support another database. Oracle? An implementation of IWrapperClassMaker could generate code for VB or any other .net language. (A config change would be required to propose the QueryFirst template for project types other than C#).

I am having this same problem. Was it ever resolved? I don't understand what to do with these two lines in the json file:
"helperAssembly":[pathToDll],
"makeSelfTest":true/false

had the same issue and just got it working by adding the QfRuntimeConnection.cs file with the following:

{
  "defaultConnection": "yourconnectionstring",
  "provider": "System.Data.SqlClient" ,
  "makeSelfTest": false
}

  • removed the helper dll line.

You don't need to worry about these options to get started. Leave out helperAssembly completely, and we won't look for one. Leave out selfTest and it defaults to false. defaultConnection and provider are absolutely necessary, otherwise we don't know what db to run your query against.