Solved

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

Posted on 2004-08-29
7
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

710 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