Link to home
Start Free TrialLog in
Avatar of jedistar
jedistarFlag for Singapore

asked on

ASP.NET connection string problem

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>
Avatar of Aneesh
Aneesh
Flag of Canada image

I am not good in .Net ; I found that u didn't mention the 'SQL server' name there.
Also try to connect to the sql server from your Query analyzer using the same username and password..
Change

dbconn = New OleDbConnection("Provider=sqloledb;Data Source=TestDB;Initial Catalog=pubs;User Id=sa;Password=test123;")


to

dbconn = New OleDbConnection("Provider=SQLNCLI;Server=TestDB;Database=pubs;UID=sa;PWD=test123;")
Avatar of jedistar

ASKER

yeah that works.. the code doesnt
Details: System.Data.OleDb.OleDbException: Login timeout expired An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. Named Pipes Provider: Could not open a connection to SQL Server [53].
StartMenu->SQL Server->Client Network Utility->What do you have in "Enabled Protocol"?

Also can you do ping TestDB from command prompt?
i'm running SQL SERVER 2005 DESKTOP ENGINE, I dont have the above Client Network Utility
Start Menu->Control Panel->Administrative Options->Data source->SystemDSN tab->Localserver->Configure->Next->Client Configuration->Which one is selected in Network Libraries
you are using oledbconnection.
better change it to System.data.sqlclient.SQLConnection
and for connection strings see this for complete list of connection strings, http://www.connectionstrings.com/
ok how abt just normal ms access
how do i access my ms access db?
whats the sql connectionstring
what's your database?

is it is MS Access database or sqlserver database?
from your connection string it seems sqlserver and connecting to pubs db.
i'm trying both.

1. could you give me a string for ms access db without password
located in c:\database\db.mdb

2. for my sql server 2005, i have the user "john" default database set to db: Test4
and i reset its password to test123

Dim dbconn As SQLConnection
dbconn = New SQLConnection("Server=PC\SQLEXPRESS;Database=Test4;User ID=john;Password=test123;Trusted_Connection=False")

i'm still getting:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'john'. The user is not associated with a trusted SQL Server connection.
try this
SQL Server
dbconn = New SQLConnection("Data Source=ipaddress\SQLEXPRESS;database=Test4;User id=john; Password=test123; Trusted_Connection=no")

Access
dbconn = new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\db.mdb;User Id=admin;Password=;" )
SQL Server, same err
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial