Solved

asp.net--- regarding connection in asp.net

Posted on 2004-08-29
7
161 Views
Last Modified: 2010-04-06
   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.

0
Comment
Question by:rmvprasad
  • 3
  • 2
7 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 11930078
because con is declared as OleDbConnection and then you are creating a new connection as SQLConnection.

What db are you using?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11930092
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
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 11930118
I can see from your connection string that you are using SQL database, so your code should be:

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection
        Dim cmd As SqlCommand
        Dim rea As SqlDataReader
        Dim SQL As String
        Dim connstr As String
        SQL = "SELECT * FROM SHIPPERS"
        CONNSTR = "data source=PRASAD;DATABASE=Northwind;Integrated Security=SSPI"
        con = New SqlConnection(CONNSTR)


        con.Open()

        cmd = New SqlCommand(SQL, con)
        rea = cmd.ExecuteReader
        ShipMethod.DataSource = rea
        ShipMethod.DataBind()

    End Sub
0
 
LVL 1

Expert Comment

by:Cart_man
ID: 11942504
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
0
 
LVL 1

Expert Comment

by:Cart_man
ID: 11942545
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.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hide or Show Images using checkbox array in mysql database 11 264
PHP parse error 7 59
WCAG (Web Content Accessibility Guidelines) levels 3 84
cookies analysis tools 2 91
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question