473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Connection to SQL Server works in VB.NET, not ASP.NET

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(cmdT ext)

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
Nov 18 '05 #1
2 1054
Suresh <an*******@discussions.microsoft.com> wrote in message news:<4D**********************************@microso ft.com>...
Try changing your connection string to,
server=DATA.MYWEBSITE.COM;uid=USER;password=PW; database=DATABASE

Hi Suresh, thanks for the security tips. That change to the
connection string did not work. My error is:
System.InvalidCastException: Specified cast is not valid. It occurs
as soon as I open the connection.

Still puzzled :-)

-Roy
Nov 18 '05 #2
Hi Roy,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you received an InvalidCastException
when trying to open an connection to the SQL server. If there is any
misunderstanding, please feel free to reply to the post.

This seems to be a very strange problem. According to the following MSDN
document, SqlConnection.Open method will never throw an
InvalidCastException.

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdatasqlclientsqlconnectionclassopentopi c.asp

Please try to check if the connection has been opened before. Please also
try to use the following connection string to connect to a default database
(Northwind) on a SQL server.

Password=PW;Persist Security Info=True;User ID=User;Initial
Catalog=Northwind;Data Source=ServerName

If this works, it means that the there might be something wrong with the
database. If it doesn't work, please use please use the SQL Profiler to
trace the actions performing on the SQL server. We might find which SQL
statement goes wrong from the trace log.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul Robinson | last post by:
I am developing a website in ASP that connects to a Sybase database. However, when I try to open a connection to the database the page will not load. The script does not timeout, nor the...
0
by: THDWWSIJQUOK | last post by:
Hi, I have an A97 database, which I have created for FTP purposes using the InetTransferLib.mda file by Dev Ashish and Terry Creft The application has worked great for me as long as I dialed-up...
7
by: mfeingold | last post by:
I am working on a system, which among other things includes a server and a ..net control sitting in an html page and connected to the server. I ran into a couple of problems, you guys might have...
5
by: Dave Dudley | last post by:
Hi, I have a new ASP .Net project that has been developed on our development machine and connects to SQL Server 2000 on the same machine. It is connecting via a connection string similiar to:...
3
by: MattM | last post by:
I am getting the "The underlying connection was closed: Unable to connect to the remote server" message when trying to connect an ASPX page to a simple Hello World web service. I have read a few...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
2
by: Ben | last post by:
Hi, I have a problem connecting to Oracle using and ODBC connection in a ASP.Net web page. The TNS Names works fine because when I create a DSN it works, and it works in SQL Plus. Here are...
5
by: OJ | last post by:
Hi, I am at a loss here, I have a c# asp.net website which connects to a remote SQL Server 2000 db via a connection string. If I set the website up in the filesystem and use the inbuilt cassini...
9
by: mel | last post by:
Hi all, I need a persistent TCP connection with my web server over page reloads. This means that, even if the user goes to a different page (in my domain), I want to keep a TCP connection...
8
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.