Results 1 to 5 of 5

Thread: SQL Connection prob from ASP [Resolved]

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2004
    Location
    KS, USA
    Posts
    34

    SQL Connection prob from ASP [Resolved]

    VB.NET 2003 and SQL 2000
    I am attempting to create a web form to query a SQL DB to post xray history using Windows authentication.
    Currently the test IIS is running on my XP PC and the SQL server is on the network (domain).

    The Form works fine when I run it from the VB Designer.
    When I run it from just a browser it fails the first time with a General Network Error. Check you Network documentation. If I try it again it works....I think because my code does not disconnect from the sql server even if I close the browser. When I get the initial error, I can look in the Ent Manager and see that I did get connected to the SQL server. I looked up the error on the Microsoft site and it says the SQL side is not configured for SSL...I don't have SSL configured on the IIS server. I do have the domain authentication turned on and the anonymous turned off in the IIS.

    So 2 questions.
    1). Why does my app get the Network Error and how do I fix it?
    2). How do I make the app close the connection to the SQL server?

    Here is my code:
    VB Code:
    1. Imports System.Data
    2. Imports System.Data.SqlClient
    3.  
    4. Public Class WebForm1
    5.     Inherits System.Web.UI.Page
    6.     'Protected WithEvents grdPatient As System.Web.UI.WebControls.DataGrid
    7.     'Declare a Connection object that is global in scope
    8.     Dim objConnection As SqlConnection
    9.  
    10.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    11.         'Put user code to initialize the page here
    12.         'Initialize the Connection Object...
    13.         objConnection = New SqlConnection("Server=TESTSQL1; Database=XRAY; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog = XRAY; ") 'Trusted_Connection = True")
    14.     End Sub
    15.  
    16.     Private Sub btnFindPatient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindPatient.Click
    17.         'Declare Objects...
    18.         Dim objDataSet As DataSet
    19.         Dim objDataAdapter As SqlDataAdapter
    20.         Dim myCmd As SqlCommand
    21.         Dim myReader As SqlDataReader
    22.         Dim RsltMedRec As String
    23.         Dim RsltRad As String
    24.         Dim RsltPatient As String
    25.         Dim RsltSex As String
    26.         Dim RsltBirthDate As String
    27.         Dim RsltSocSec As String
    28.         Dim RsltLastExam As String
    29.         Dim strMed_REC As String
    30.  
    31.         'Assign the value in the input box to the query variable
    32.         strMed_REC = txtGetMedRec.Text
    33.  
    34.         'Create a SQL Command Object to query Patient by MedRec number
    35.         myCmd = objConnection.CreateCommand
    36.         myCmd.CommandText = "SELECT Med_Rec#, RAD#, First_Name," & _
    37.         "Last_Name, Sex, Birth_Date, Soc_Sec#, Last_Exam_Date " & _
    38.         "From tblPatient " & _
    39.         "WHERE Med_Rec#= '" & strMed_REC & "'"
    40.  
    41.         objConnection.Open()
    42.         myReader = myCmd.ExecuteReader()
    43.  
    44.         'Place the query Results into the result strings
    45.         Do While myReader.Read()
    46.             RsltMedRec = myReader.GetString(0)
    47.             RsltRad = myReader.GetString(1)
    48.             RsltPatient = myReader.GetString(3) & ", " & myReader.GetString(2)
    49.             RsltSex = myReader.GetString(4)
    50.             RsltBirthDate = myReader.GetString(5) & "   "
    51.             RsltSocSec = myReader.GetString(6)
    52.             RsltLastExam = myReader.GetString(7)
    53.         Loop
    54.  
    55.         'Display Results on the web form...
    56.         lblMedRec.Text = RsltMedRec
    57.         lblRad.Text = RsltRad
    58.         lblPatient.Text = RsltPatient
    59.         lblSex.Text = RsltSex
    60.         lblBirthDate.Text = RsltBirthDate
    61.         lblSocSec.Text = RsltSocSec
    62.         lblLastExam.Text = RsltLastExam
    63.         'Close(DataReader)
    64.         objConnection.Close()
    65.  
    66.         'Set the SQL Query String to pull all the procedures...
    67.         objDataAdapter = New SqlDataAdapter("SELECT Proc_Date_Time as 'Proc Date/Time'," & _
    68.         "Dept, PROC#, Proc_Description As 'Proc Desc'," & _
    69.         "Ordering_Phy_Last As 'Order Phy LastName'," & _
    70.         "Ordering_Phy_Firs As 'Order Phy FirstName'" & _
    71.         "FROM tblProcedure WHERE Med_Rec# = '" & strMed_REC & "'" & _
    72.         "Order By Proc_Date_Time DESC", objConnection)
    73.  
    74.         'Initialize the DataSet object and fill it...
    75.         objDataSet = New DataSet
    76.         objDataAdapter.Fill(objDataSet, "tblProcedure")
    77.  
    78.         'Declare a DataView Object, populate it, and sort the data in it...
    79.         Dim objDataView As DataView = objDataSet.Tables("tblProcedure").DefaultView
    80.         grdPatient.DataSource = objDataView
    81.         grdPatient.DataBind()
    82.         'Close Connection
    83.         objConnection.Close()
    84.     End Sub
    85. End Class

    The error is on line 79: MyReader = myCmd.ExecuteReader()
    TIA, I am a wooky, oops I mean rookie! - Jeff
    Last edited by rothjm; Jun 3rd, 2005 at 12:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width