Solved

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

Posted on 2004-08-29
7
164 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

636 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