Link to home
Start Free TrialLog in
Avatar of rmvprasad
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=Northwind;Integrated Security=SSPI"
        con = New SqlConnection(CONNSTR)

        'con.Open()
        Response.Write(con.ConnectionString)
        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.

Avatar of YZlat
YZlat
Flag of United States of America image

because con is declared as OleDbConnection and then you are creating a new connection as SQLConnection.

What db are you using?
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
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America 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
Avatar of Cart_man
Cart_man

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
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.