rmvprasad
asked on
asp.net--- regarding connection in asp.net
Sir/Madam,
Can you please let me know why this code is not working.This is not getting connected .
dim con as oledbconnection
dim cmd as oledbcommand
dim rea as oledbreader
dim connstr as string
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SQL = "SELECT * FROM SHIPPERS"
CONNSTR = "data source=PRASAD;DATABASE=Nor thwind;Int egrated Security=SSPI"
con = New SqlConnection(CONNSTR)
'con.Open()
Response.Write(con.Connect ionString)
con.Open()
cmd = New SqlCommand(SQL, con)
REA = cmd.ExecuteReader
ShipMethod.DataSource = REA
ShipMethod.DataBind()
End Sub
Login failed for user 'PRASAD\ASPNET'.
getting error at con.open().Can you tell me why
thankyou.
Can you please let me know why this code is not working.This is not getting connected .
dim con as oledbconnection
dim cmd as oledbcommand
dim rea as oledbreader
dim connstr as string
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SQL = "SELECT * FROM SHIPPERS"
CONNSTR = "data source=PRASAD;DATABASE=Nor
con = New SqlConnection(CONNSTR)
'con.Open()
Response.Write(con.Connect
con.Open()
cmd = New SqlCommand(SQL, con)
REA = cmd.ExecuteReader
ShipMethod.DataSource = REA
ShipMethod.DataBind()
End Sub
Login failed for user 'PRASAD\ASPNET'.
getting error at con.open().Can you tell me why
thankyou.
if you are using access db, replace
cmd = New SqlCommand(SQL, con)
with
cmd = New OleDbCommand(SQL, con)
and if you are using SQL Server db, replace
Dim con As oledbconnection
Dim cmd As oledbcommand
Dim rea As oledbreader
with
Dim con As SQLconnection
Dim cmd As SQLcommand
Dim rea As SQLDataReader
Also
dim rea as oledbreader
should be
dim rea as oledbDataReader
cmd = New SqlCommand(SQL, con)
with
cmd = New OleDbCommand(SQL, con)
and if you are using SQL Server db, replace
Dim con As oledbconnection
Dim cmd As oledbcommand
Dim rea As oledbreader
with
Dim con As SQLconnection
Dim cmd As SQLcommand
Dim rea As SQLDataReader
Also
dim rea as oledbreader
should be
dim rea as oledbDataReader
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The connection string does not specify a user name and a password. That implies that the ASPNET user must have access to the database against which you run the query. Either allow ASPNET access to the database
-OR (and i recommend you do this)-
- Create a new user let's say user1 and give him access to the database and set a password let's say pass1
- Change the CONNSTR to: CONNSTR = "server=PRASAD; db=Northwind; uid=user1; pwd=pass1"
Good luck
-OR (and i recommend you do this)-
- Create a new user let's say user1 and give him access to the database and set a password let's say pass1
- Change the CONNSTR to: CONNSTR = "server=PRASAD; db=Northwind; uid=user1; pwd=pass1"
Good luck
Another excellent tip for building a connection string is:
create a new empty file called let's say x.udl.
Doule-click it, and a dialog box appears. Enter the properties of the server.
After you're done open the file with Notepad and you'll have a perfect connection string.
create a new empty file called let's say x.udl.
Doule-click it, and a dialog box appears. Enter the properties of the server.
After you're done open the file with Notepad and you'll have a perfect connection string.
What db are you using?