Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

problem connecting to my database behind a firewall

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg W - 16 Jul 2005 20:48 GMT
hello all,
I have site that I just moved to a new host.  It is a dedicated server that
sits behind a dedicated firewall.  Most of the site uses classic ASP that are
working fine but I have some parts that I am converting to .NET that can't
seem to access the database.

The server is windows 2k3 and I am using SQL Server 2k.  

In my web config file I have the following connection string:

<appSettings>
 <add key="emailConn" value="workstation id=SAVAGE;packet size=4096;user
id=xxx;data source=[ip];persist security info=True;initial
catalog=email;password=xxx" />
 </appSettings>

Here is the code where I am calling the connection and using it:

Dim txtUser As String = Request.Form("strUserID")
           Dim txtPW As String = Trim(Request.Form("strPassword"))
           Dim txtPWdb As String
           Dim intAdmindb, intDirdb As Integer

           Dim cmdPW As New SqlCommand("SELECT strPWD, intAdmin, intDirector
FROM dbo.prtlUser WHERE (strUID)='" & txtUser & "'")

           Dim objCon As New SqlConnection(ConfigurationSettings.AppSettings
("emailConn"))

               cmdPW.Connection = objCon
               cmdPW.Connection.Open()

               Dim readPW As SqlDataReader = cmdPW.ExecuteReader()
               Do While readPW.Read()
                   txtPWdb = readPW(0)
                   intAdmindb = readPW(1)
                   intDirdb = readPW(2)
               Loop
               If txtPW = txtPWdb And txtPW <> "" Then
                   Dim strUIDs As String
                   Session("strUIDs") = txtUser
                   Session("intAdmins") = intAdmindb
                   Session("intDirs") = intDirdb
                   Response.Redirect("default.aspx")
               Else
                   Panel1.Visible = False
                   Panel2.Visible = True
               End If

               objCon.Close()

As you can see this is a log in page where some one enters a log in and pw
and it checks to see if it is a valid match.

In my classic ASP stuff, since I am behind the firewall instead of using the
external ip of the server I use the internal one 192.168.0.2.  However, on
the new server, I have tried using the external IP (this worked with the old
server), the internal IP, and even setting the datasource as things like
localhost and (local).  Everytime I get the following error:

SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: SQL Server does not
exist or access denied.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.  

At first I thought it might be a permissions error, but when I set the
connection string in the config file to the external IP, and I run this on my
local machine, it can connect to the database and run with no problem.  I am
convinced it has something to do with the firewall, but I have no idea what
to do about it.

Any help would be greatly appreciated.
Mariano Omar Rodriguez - 17 Jul 2005 00:38 GMT
It seems to be a Networking problem. You need check if you want network
connection to the database server.

Mariano

> hello all,
> I have site that I just moved to a new host.  It is a dedicated server
[quoted text clipped - 89 lines]
>
> Any help would be greatly appreciated.
a22042 - 17 Jul 2005 15:51 GMT
> *It seems to be a Networking problem. You need check if you want
> network
[quoted text clipped - 3 lines]
>
> *

Im sorry, i don't follow.  The SQL Server is running on the same
machine as the web server  In classic ASP I can connect to the db with
no problem, it is just in .NET I have a problem.


Alan Samet - 17 Jul 2005 21:12 GMT
I would start by just trying to get your application to connect to the
database. Try creating a new page with the following code, update your
ip, uid and password parameters. I have a feeling it's something simple
that you may be overlooking -- the first thing I'd recommend is that
you verify your connection string and your appsetting (I'm winging it
here, hopefully there's no syntax errors):

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat=server>
 Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
   With New
SqlConnection("server=[ip];database=master;uid=xxx;password=xxx;")
     .Open()
     .Close()
   End With
 End Sub
</script>
Greg W - 18 Jul 2005 01:47 GMT
OK, that worked, but I cant see why it wont work in the app.  It worked fine
on the other server.  And when I debug from my local machine (and use the
external ip) it works fine as well.

>I would start by just trying to get your application to connect to the
>database. Try creating a new page with the following code, update your
[quoted text clipped - 14 lines]
>  End Sub
></script>
Alan Samet - 18 Jul 2005 14:15 GMT
I'm wondering if it's a deployment issue. If you're using codebehinds,
have you deployed the compiled dll to the bin directory of the server?
Also, verify that your web.config is updated.

-Alan
Greg W - 18 Jul 2005 20:40 GMT
Oh crap, thank you very much, I thought I had coppied over the the bin folder,
but must have forgotten, that is exactly it.

>I'm wondering if it's a deployment issue. If you're using codebehinds,
>have you deployed the compiled dll to the bin directory of the server?
>Also, verify that your web.config is updated.
>
>-Alan
Alan Samet - 19 Jul 2005 23:28 GMT
I thought that may've been it. I'd say that belongs near or at the top
of the list for common ASP.NET oversights that cause developers a lot
of frustration :)

-Alan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.