Connection problem with SqlClient

  • Thread starter Thread starter Tony Zoccolillo
  • Start date Start date
T

Tony Zoccolillo

I have a SQL Server database on a Windows 2000 Server. I have IIS running
on a 2nd 2000 Server with no SQL Server on it.. Neither are the PDC. Both
servers have the most recent .NET framework installed.

When I try to connect from my aspx page using SqlClient I get an error right
away. My code looks something like...

Imports System.Data.SqlClient

Dim Conn2 As New SqlClient.SqlConnection("Data
Source=10.10.10.101,1433;Initial Catalog=MapLayers; UID=coresqluser;
PWD=OeQu_!102")
Dim cmd As SqlClient.SqlCommand
Dim objDataReader As SqlClient.SqlDataReader
Dim strSQL As String
Dim basename As String
Dim appt As String
Dim last_upd As String
Dim n As Integer

appt = Request.QueryString("atype")
basename = Request.QueryString("thebase")

Conn2.Open()

strSQL = "SELECT * from site_name WHERE site_name.site_id = '" & basename &
"';"
cmd = New SqlClient.SqlCommand(strSQL, Conn2)
objDataReader = cmd.ExecuteReader


It errors on the "Imports" line....If I remove it, I get am error on the
first DIM. It seems the problem is with the SqlClient class. If I put .NET
framework on a machine without SQL Server, are these connectors installed?

I'm confident my connection params are valid. I've also tried using the
machine name rather than IP.

Any ideas or suggestions would be appreciated,

Tony Zoccolillo
 
Tony
Make sure to add your references System and System.Data... when you do this you should have no problems. I tested your code and it seems to work fine. If you have to use an imports statement make sure it is above the Public Class Statement

Also, I looked at your code... you may want to look at using stored procedures... it's faster and much more secure. Oh... hope that isn't your real connection string... if it is you might want to change it

Hope this was helpful.
 
Thanks...no, not the real conection string. I use strored procs all them
time with ADO and ASP but I'm just getting into .NET and still learning the
basics. I have use auto-generated stored procs with vb.net data adapters,
but not with asp.net yet. This app is just a data driven toolbar and only
return 2-5 records...also being run on new 2x3GHz Dell servers on a
fiberoptic gigabyte network...all for 20-30 potential users...in a GIS
system, so the SQL call isn't much of a bottleneck...

I do have System and System.Data referenced, amoung others, but they are set
to Copy Local = False. Shouldn't they already be on a system wth .NET
Framework installed? If I set the Copy Local to true it puts a copy of the
dll in my bin for distribution, correct? This is probably worth doing at
least as a test of the remote system.

Thanks,
TZ


Bryan said:
Tony,
Make sure to add your references System and System.Data... when you do
this you should have no problems. I tested your code and it seems to work
fine. If you have to use an imports statement make sure it is above the
Public Class Statement.
Also, I looked at your code... you may want to look at using stored
procedures... it's faster and much more secure. Oh... hope that isn't your
real connection string... if it is you might want to change it.
 
Copy local should be fine... I normally have that set to false. What exactly is the error message you receieve from your comipiler? System and Syste.Data are the important references. They normally are referenced when a new project is created. I'm wondering about the error message... can you post it?
 
If this code is in the page itself, not in the code-behind file, then you
cannot do an Imports (or using for C# uses) right there. Instead, add the
following to the page header, right after the @page directive:

<%@ Import namespace="System.Data.SqlClient" %>

You can add more of these lines for each of the namespaces you'd like to
import.

--
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
I solved the problem by setting CopyLocal to true and copying the dlls over
in the bin directory. Apparently the .NET framework on the server has a
problem (?) in that the System.Data is not being found. Does it need to be
in a virtual path or something?

The error I was getting was on the dim of thew SqlClient.SqlConnection. The
object was unknown...because the dll was missing or not found. That's why
I'm thinking maybe it should be in a virtual folder of the website so web
apps can find it.

Thanks,
TZ




Bryan said:
Copy local should be fine... I normally have that set to false. What
exactly is the error message you receieve from your comipiler? System and
Syste.Data are the important references. They normally are referenced when
a new project is created. I'm wondering about the error message... can you
post it?
 
The code was in the code-behind page. I think there is a problem on the
server with the .NET framework install, or maybe I need to have a virtual
dir on the website to find the System.Data DLL. I solved the problem by
setting CopyLocal to true and moved the dll over with my bind directory. I
wouldn't think this would be neccessary as I assumed .NET framework
installation would make this lib available for apps.

TZ
 
Back
Top