R
Roy Lawson
I am using SQL Server authentication (as opposed to Windows
authentication) to connect to a database and fill a dataset. I am
able to do this fine in VB, but not ASPx. I would think it to be
security if I were using integrated authentication, but since I am
using SQL authentication I am not sure.
Here is what i pass in to the class:
'### strCon is actually a dynamic property from a web.config key.
'### it looks like this:
'### "data source=DATA.MYWEBSITE.COM;initial
'### catalog=DATABASE;password=PW;user id=USER"
myInt = myCls.Authenticate(strCon, strLogin, strPW,
strProperty)
'### The class file (Authenticate) looks like so:
Imports System.Data
Imports System.Data.SqlClient
Public Class clsAuthenticate
Public Function Authenticate(ByVal strCon As String, ByVal
strLogin As String, ByVal strPW As String, ByVal strProperty As
String) As Integer
Dim oConnection As New SqlConnection(strCon)
Dim cmdText As String = "SELECT * FROM viewLogin WHERE
viewLogin.username = '" & strLogin & "' AND viewLogin.password = '" &
strPW & "' AND viewLogin.company_cd = '" & strProperty & "'"
Dim oDataAdapter As New
System.Data.SqlClient.SqlDataAdapter(cmdText, oConnection)
Dim oDS As New Data.DataSet()
Dim myResult As Integer
oDataAdapter.SelectCommand.CommandText.Equals(cmdText)
Try
'Fill the dataset
oConnection.Open() '### This is where the ERROR occurs ###
oDataAdapter.Fill(oDS, "viewLogin")
oConnection.Close()
Dim SecLevel As String
Dim Row As DataRow
Row = oDS.Tables("viewLogin").Rows(0)
SecLevel = Row.Item("SecurityRoleID")
myResult = CType(SecLevel, Integer)
oDS.Reset()
Return myResult
Catch e As Exception
'MsgBox(e.ToString)
Dim myex As String = e.ToString
Return 99
End Try
End Function
End Class
authentication) to connect to a database and fill a dataset. I am
able to do this fine in VB, but not ASPx. I would think it to be
security if I were using integrated authentication, but since I am
using SQL authentication I am not sure.
Here is what i pass in to the class:
'### strCon is actually a dynamic property from a web.config key.
'### it looks like this:
'### "data source=DATA.MYWEBSITE.COM;initial
'### catalog=DATABASE;password=PW;user id=USER"
myInt = myCls.Authenticate(strCon, strLogin, strPW,
strProperty)
'### The class file (Authenticate) looks like so:
Imports System.Data
Imports System.Data.SqlClient
Public Class clsAuthenticate
Public Function Authenticate(ByVal strCon As String, ByVal
strLogin As String, ByVal strPW As String, ByVal strProperty As
String) As Integer
Dim oConnection As New SqlConnection(strCon)
Dim cmdText As String = "SELECT * FROM viewLogin WHERE
viewLogin.username = '" & strLogin & "' AND viewLogin.password = '" &
strPW & "' AND viewLogin.company_cd = '" & strProperty & "'"
Dim oDataAdapter As New
System.Data.SqlClient.SqlDataAdapter(cmdText, oConnection)
Dim oDS As New Data.DataSet()
Dim myResult As Integer
oDataAdapter.SelectCommand.CommandText.Equals(cmdText)
Try
'Fill the dataset
oConnection.Open() '### This is where the ERROR occurs ###
oDataAdapter.Fill(oDS, "viewLogin")
oConnection.Close()
Dim SecLevel As String
Dim Row As DataRow
Row = oDS.Tables("viewLogin").Rows(0)
SecLevel = Row.Item("SecurityRoleID")
myResult = CType(SecLevel, Integer)
oDS.Reset()
Return myResult
Catch e As Exception
'MsgBox(e.ToString)
Dim myex As String = e.ToString
Return 99
End Try
End Function
End Class