troubleshooting Question

ASP.NET connection string problem

Avatar of jedistar
jedistarFlag for Singapore asked on
Microsoft SQL Server
16 Comments1 Solution545 ViewsLast Modified:
hi,

i'm coding asp.net on my .aspx form to connect to my MS SQL Server 2005.
but the error is:

Exception Details: System.Data.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.


I added my permissions properly..
is my codes correct?

my codes in index.aspx is:
...
Sub Login(sender As Object, e As ImageClickEventArgs)
...
            Dim dbconn As Oledbconnection
            dbconn = New OleDbConnection("Provider=sqloledb;Data Source=TestDB;Initial Catalog=pubs;User Id=sa;Password=test123;")
      
            dbconn.Open()                                          'Opens Database Connection
            Dim strCommand As String                    'Declarations for Database Variables
            Dim odbcmd As New OleDbCommand
            Dim dtrResults As OleDBDataReader                
            'Retrieves Email and Password from Database
            strCommand = "SELECT * From Users WHERE Username =”& “@User AND Password = @Pass "               
            odbcmd = New OleDbCommand(strCommand, dbconn)
      
            odbcmd.Parameters.Add("@User", OleDbType.VarChar, 255)
            odbcmd.Parameters.Add("@Pass", OleDbType.VarChar, 255)
            odbcmd.Parameters("@User").Value = txtUsername.text
            odbcmd.Parameters("@Pass").Value = txtPasswd.text
                  
            'Reads Results from Retrieval
            dtrResults = odbcmd.ExecuteReader()
            
            'Redirecting Admin or User to respective URL
            If dtrResults.Read()
                  Session("FirstName") = dtrResults("FirstName")
                  Session("ID") = dtrResults("id")
            'Email and Password mismatch
            Else                                    
                  lblErrorMsg.text = "*Please enter a valid email or password!"
            End If        
            dbconn.Close()    'Close database connection
End Sub
</script>
ASKER CERTIFIED SOLUTION
appari

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros