SQLconnection problem

  • Thread starter Thread starter jay
  • Start date Start date
J

jay

I'm pretty new to asp.net and I'm having trouble just trying to set up
a basic SQLconnection within visual studio, I'm sure the problem must
be something basic but I can't seem to find it.

The problem is that the connection string ("Integrated
Security=yes;Initial Catalog=Northwind;Data Source=(local)") is
underlined within the code editor and provides the error text 'Too many
arguements for 'Public Sub New()' when you hover over the text.

a snippet of the code is below:

Imports System.Data
Imports System.Data.SqlClient

' ----- within the page_load function ------
Dim sqlConnection As SQLConnection

sqlConnection = New SqlConnection("Integrated Security=yes;Initial
Catalog=Northwind;Data Source=(local)")
 
Comments inline:
jay said:
I'm pretty new to asp.net and I'm having trouble just trying to set up
a basic SQLconnection within visual studio, I'm sure the problem must
be something basic but I can't seem to find it.

The problem is that the connection string ("Integrated
Security=yes;Initial Catalog=Northwind;Data Source=(local)") is
underlined within the code editor and provides the error text 'Too many
arguements for 'Public Sub New()' when you hover over the text.

a snippet of the code is below:

Imports System.Data
Imports System.Data.SqlClient

' ----- within the page_load function ------
Dim sqlConnection As SQLConnection

sqlConnection = New SqlConnection("Integrated Security=yes;Initial
Catalog=Northwind;Data Source=(local)")
--Jay, is this the exact line? Typically if you see this problem in this
context, it thinks your passing in another parameter somehwere - the
constructor here should take just one string argument. If for some reason
you had an extra " in there or something like that which made it think there
were two strings, that could be a problem. Also, if it's continued on the
second line without a continuation character, that could be a potential
problem as well. Just to diagnose it, I'd create a String (name
connection_string for instnace) that's a constant and then set the value
there. Then in your constructor use
sqlConnection = New SqlConnection(CONNECTION_STRING). This is a 'good'
practice anyway and will help diagnose the problem. If you have one single
string going in as the constructor's only parameter, that should fix it.
BTW, since this is an ASP.NET app, if you're using a trusted connection,
you're going to need to use Impersonation , otherwise it won't be able to
generate a SSPI context and you won't be able to open the connection. This
isn't the problem here but it will be one once you get this solved ifyou
don't have impersonation in place. Also, I'd use a string variable to hold
the connection string, but you want to look to using web.config/app.config
or method to allow you to change it without having to recompile your
application. Again, this isnt' the problem but it's something you'll face
in the near future. Double check the line continuation, that you don't have
anyt other params and that it's being considered one string, that should fix
the immediate problem - if not, let me know and we'll proceed from there.
 
Back
Top