Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-29
7
Medium Priority
?
165 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 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

705 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