Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceError with DbCommand created before opening Connection #180

Closed
ThijsKoot opened this issue Dec 12, 2019 · 1 comment
Closed
Labels

Comments

@ThijsKoot
Copy link
Contributor

Issue description

When a DbCommand is created from a connection before the connection has been opened a first time, executing the DbCommand results in a NullReferenceException. This is because the SnowflakeDbCommand-constructor assigns the value of the sfSession-property of SnowflakeDbConnection to itself. The problem here is that sfSession is set when opening the connection, meaning that DbCommand assigns a null value if the connection has never been opened. I'm creating a pull request with a fix for this.

Example code

using (var conn = new SnowflakeDbConnection { ConnectionString = connstr })
{
	var cmd = conn.CreateCommand();
	cmd.CommandText = "select current_version()";
	
	conn.Open();
	
	var result = cmd.ExecuteScalar();
	
	conn.Close();
}

Error log

Not required, problem is in the connector itself.

Configuration

Driver version: 1.1.0

Dotnet framework and version: .net standard 2.0

ThijsKoot pushed a commit to ThijsKoot/snowflake-connector-net that referenced this issue Dec 12, 2019
ChTimTsubasa pushed a commit that referenced this issue Feb 26, 2020
ChTimTsubasa pushed a commit that referenced this issue Feb 26, 2020
@ChTimTsubasa
Copy link
Contributor

Thank you for reporting this issue and submitting a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants