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 dont 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:
The error is on line 79: MyReader = myCmd.ExecuteReader()
Thanks for any assistance! Jeff
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 dont 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:
Code:
visual basic code:
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents grdPatient As System.Web.UI.WebControls.DataGrid
Declare a Connection object that is global in scope
Dim objConnection As SqlConnection
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Put user code to initialize the page here
Initialize the Connection Object...
objConnection = New SqlConnection("Server=TESTSQL1; Database=XRAY; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog = XRAY; ") Trusted_Connection = True")
End Sub
Private Sub btnFindPatient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindPatient.Click
Declare Objects...
Dim objDataSet As DataSet
Dim objDataAdapter As SqlDataAdapter
Dim myCmd As SqlCommand
Dim myReader As SqlDataReader
Dim RsltMedRec As String
Dim RsltRad As String
Dim RsltPatient As String
Dim RsltSex As String
Dim RsltBirthDate As String
Dim RsltSocSec As String
Dim RsltLastExam As String
Dim strMed_REC As String
Assign the value in the input box to the query variable
strMed_REC = txtGetMedRec.Text
Create a SQL Command Object to query Patient by MedRec number
myCmd = objConnection.CreateCommand
myCmd.CommandText = "SELECT Med_Rec#, RAD#, First_Name," & _
"Last_Name, Sex, Birth_Date, Soc_Sec#, Last_Exam_Date " & _
"From tblPatient " & _
"WHERE Med_Rec#= " & strMed_REC & ""
objConnection.Open()
myReader = myCmd.ExecuteReader()
Place the query Results into the result strings
Do While myReader.Read()
RsltMedRec = myReader.GetString(0)
RsltRad = myReader.GetString(1)
RsltPatient = myReader.GetString(3) & ", " & myReader.GetString(2)
RsltSex = myReader.GetString(4)
RsltBirthDate = myReader.GetString(5) & " "
RsltSocSec = myReader.GetString(6)
RsltLastExam = myReader.GetString(7)
Loop
Display Results on the web form...
lblMedRec.Text = RsltMedRec
lblRad.Text = RsltRad
lblPatient.Text = RsltPatient
lblSex.Text = RsltSex
lblBirthDate.Text = RsltBirthDate
lblSocSec.Text = RsltSocSec
lblLastExam.Text = RsltLastExam
Close(DataReader)
objConnection.Close()
Set the SQL Query String to pull all the procedures...
objDataAdapter = New SqlDataAdapter("SELECT Proc_Date_Time as Proc Date/Time," & _
"Dept, PROC#, Proc_Description As Proc Desc," & _
"Ordering_Phy_Last As Order Phy LastName," & _
"Ordering_Phy_Firs As Order Phy FirstName" & _
"FROM tblProcedure WHERE Med_Rec# = " & strMed_REC & "" & _
"Order By Proc_Date_Time DESC", objConnection)
Initialize the DataSet object and fill it...
objDataSet = New DataSet
objDataAdapter.Fill(objDataSet, "tblProcedure")
Declare a DataView Object, populate it, and sort the data in it...
Dim objDataView As DataView = objDataSet.Tables("tblProcedure").DefaultView
grdPatient.DataSource = objDataView
grdPatient.DataBind()
Close Connection
objConnection.Close()
End Sub
End Class
The error is on line 79: MyReader = myCmd.ExecuteReader()
Thanks for any assistance! Jeff