bbsimonbb/query-first

Empty classes generation even if tables are full of query results

Closed this issue · 8 comments

Created a sample database after installing query-first. Tried multiple times with multiple tables and data variations but still empty classes.

VS 2015 Community

Convince me this is an issue. What did you try? Is the extension properly installed? Do you see the Query First template? Do you see the Tools => Merde... command? Have you configured your data sources? Do you see any output when you save a .sql created with the template?

Yes, the extensions is properly installed. I see the QF template and Merde! command. I have also configured the data sources and output window shows errors.
ScreentShot for my current configuration:
image

Results from output window:
Registering types...
Registered types...
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 255Object 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 255Object 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 255Object 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 120Object 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

The output files are:
Gen.cs>>>
/* Generated code goes here. Don't bother modifying this file */
Results.cs>>>
using System;

namespace HelloDapper
{
[Serializable]
public partial class Query1Results
{
// Partial class extends the generated results class
// Serializable by default, but you can change this here
// Put your methods here :-)
internal void OnLoad()
{
}
}
}

PS. I am moving to a new city so will take some time to respond and might do a fork

Did you put this code in the same namespace as your SQL?

For example:

using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace ProjectName.Sql
{
	class QfRuntimeConnection
	{
		public static IDbConnection GetConnection()
		{
			return new SqlConnection(ConfigurationManager.ConnectionStrings["QfRuntimeConnection"].ConnectionString);
		}
	}
}

@TGMarkPalnau Yes, I have also tried with putting a get connection in same namespace and another with .Sql appended.

Your output claims the error is on line 36, which is this:
provider = tiny.Resolve<IProvider>(DesignTimeConnectionString.v.ProviderName);

Which suggests to me that there is a problem with the design type connection string.

In my config file I have the following connection strings:

<add name="QfDefaultConnection" connectionString="server=SQLSERVER2014;initial catalog=MyDatabase;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
<add name="QfRuntimeConnection" connectionString="server=SQLSERVER2014;initial catalog=MyDatabase;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>

You could just use the default connection in your runtime connection class technically, but QueryFirst is hardcoded to look for QfDefaultConnection.

Please check that: 1) you have the providerName included in the connection, 2) The spelling of "QfDefaultConnection" and 3) the connection string is correct

I have a feeling if all of this checks out, it will work 😉

It is some progress after adding the connection string but now i get this error in ge.cs
Error running query.

/*The last attempt to run this query failed with the following error. This class is no longer synced with the query
You can compile the class by deleting this error information, but it will likely generate runtime errors.

Instance failure.

at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, Boolean isFirstTransparentAttempt, SqlAuthenticationMethod authType, Boolean disableTnir)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover, Boolean isFirstTransparentAttempt, Boolean disableTnir)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at QueryFirst.Providers.SqlClient.FindUndeclaredParameters(String queryText) in C:\mydev\QueryFirstV\QueryFirst\Providers\SqlClient.cs:line 77
at QueryFirst.Conductor.ProcessOneQuery(Document queryDoc) in C:\mydev\QueryFirstV\QueryFirst\Conductor.cs:line 98
*/
Error running query.

/*The last attempt to run this query failed with the following error. This class is no longer synced with the query
You can compile the class by deleting this error information, but it will likely generate runtime errors.

Instance failure.

at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at QueryFirst.Providers.SqlClient.FindUndeclaredParameters(String queryText) in C:\mydev\QueryFirstV\QueryFirst\Providers\SqlClient.cs:line 77
at QueryFirst.Conductor.ProcessOneQuery(Document queryDoc) in C:\mydev\QueryFirstV\QueryFirst\Conductor.cs:line 98
*/

Now it looks like a connection error with a timeout. Can you connect to the database using the connection string outside of the queryfirst code? Maybe you need a username and password instead of windows integrated security? I would also clean/build your project at this point just to be sure nothing else is going on.

Nothing here too troubling. I need to improve the error message for invalid provider. I propose to close...