Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlconnection is not defined

Tags:

.net

vb.net

I am trying to update some code. I have a vb file that begins with this...

Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports System.Configuration

<script runat="server">

...and it is failing here...

Using oConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("tps_write").ConnectionString())

The error it returns is...

"Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'SqlConnection' is not defined."

Am I missing some system class?

EDIT: I updated the code to this...

Using oConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("tps_write").ConnectionString())

...and it accepts it. Why do I need to explicitly write out System.Data.SqlClient every time I use an object from that class???

like image 860
Mr. Ant Avatar asked Nov 05 '22 04:11

Mr. Ant


2 Answers

EDIT: I updated the code to this...

Using oConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("tps_write").ConnectionString())

...and it accepts it. Why do I need to explicitly write out System.Data.SqlClient every time I use an object from that class???

My best guess is that there's another class out there called SqlConnection and .NET doesn't know which type to use until you specify the System.Data.SqlClient.SqlConnection one explicitly.

like image 59
Jason Towne Avatar answered Nov 09 '22 17:11

Jason Towne


So, it turns out this line was the issue...

Using oConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("tps_write").ConnectionString())

...instead of using "tps_write," I changed the permission to "tpsWrite." Apparently the tps_write is an outdated permission no longer used here at work. I wish the error messages were more clear. ;)

Thanks for everyone's help!

like image 34
Mr. Ant Avatar answered Nov 09 '22 16:11

Mr. Ant