jedistar
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.OleDbExc eption: [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;D ata 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("@Us er", OleDbType.VarChar, 255)
odbcmd.Parameters.Add("@Pa ss", 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>
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.OleDbExc
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=
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("@Us
odbcmd.Parameters.Add("@Pa
odbcmd.Parameters("@User")
odbcmd.Parameters("@Pass")
'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>
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;D ata Source=TestDB;Initial Catalog=pubs;User Id=sa;Password=test123;")
to
dbconn = New OleDbConnection("Provider= SQLNCLI;Se rver=TestD B;Database =pubs;UID= sa;PWD=tes t123;")
dbconn = New OleDbConnection("Provider=
to
dbconn = New OleDbConnection("Provider=
ASKER
yeah that works.. the code doesnt
ASKER
Details: System.Data.OleDb.OleDbExc eption: 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?
Also can you do ping TestDB from command prompt?
ASKER
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->Configur e->Next->C lient Configuration->Which one is selected in Network Libraries
you are using oledbconnection.
better change it to System.data.sqlclient.SQLC onnection
and for connection strings see this for complete list of connection strings, http://www.connectionstrings.com/
better change it to System.data.sqlclient.SQLC
and for connection strings see this for complete list of connection strings, http://www.connectionstrings.com/
ASKER
ok how abt just normal ms access
how do i access my ms access db?
how do i access my ms access db?
ASKER
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.
is it is MS Access database or sqlserver database?
from your connection string it seems sqlserver and connecting to pubs db.
ASKER
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\S QLEXPRESS; Database=T est4;User ID=john;Password=test123;T rusted_Con nection=Fa lse")
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.SqlE xception: Login failed for user 'john'. The user is not associated with a trusted SQL Server connection.
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\S
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.SqlE
try this
SQL Server
dbconn = New SQLConnection("Data Source=ipaddress\SQLEXPRES S;database =Test4;Use r 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
dbconn = New SQLConnection("Data Source=ipaddress\SQLEXPRES
Access
dbconn = new oledbconnection("Provider=
ASKER
SQL Server, same err
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.