1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to connect with database?

Discussion in 'Databases' started by honeyclarck, Mar 29, 2012.

  1. #1
    I am newbie in this field and facing some problem. Please some one can tell or give the code to connect with database in ASP.NET?
     
    honeyclarck, Mar 29, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    EricBruggema, Apr 1, 2012 IP
  3. tiffanywilliams12i2

    tiffanywilliams12i2 Peon

    Messages:
    164
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what kind of error messageS?
     
    tiffanywilliams12i2, Apr 6, 2012 IP
  4. calflowers

    calflowers Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I agree with Eric. You will have better use of your time by searching on Google instead of waiting for replies here.
     
    calflowers, Apr 9, 2012 IP
  5. abdurrahman

    abdurrahman Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    i don't know which database u want to connect,but in oracle to connect with yr db following query are used..
    ]$ export ORACLE_SID=databasename linux os
    ]$sqlplus / as sysdba
    sql>startup
     
    abdurrahman, May 19, 2012 IP
  6. abdurrahman

    abdurrahman Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    this above query offcource helped for cnnect with your database.......
     
    abdurrahman, May 22, 2012 IP
  7. salma98210

    salma98210 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    We are going to use the Northwind database in our examples.
    First, import the "System.Data.OleDb" namespace. We need this namespace to work with Microsoft Access and other OLE DB database providers. We will create the connection to the database in the Page_Load subroutine. We create a dbconn variable as a new OleDbConnection class with a connection string which identifies the OLE DB provider and the location of the database. Then we open the database connection:
     
    salma98210, May 26, 2012 IP
  8. dellmerca

    dellmerca Banned

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #8
    Try this asp.net database connection sample.....
    http://asp.net-informations.com/ado.net/asp-database-program.htm

    Dell
     
    dellmerca, Nov 26, 2014 IP
  9. Naina S

    Naina S Active Member

    Messages:
    203
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    93
    #9
    use web.config to store the connection string like this -
    <connectionStrings>
    <add name="saCS" connectionString="Data Source=MyDatabase.db.105435095.hostedresource.com;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=MyDatabase;Password=vewxas9tn0M4@" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    Explanation -
    saCS - connection string name .
    Data Source - database server location
    Initial Catalog - database name
    User ID - your database user id
    password - its password

    Use this connection string in your c# page to make the connection like -

    SqlConnection conn;
    SqlCommand cmd;
    SqlDataAdapter sqlDataAdapter;
    DataSet dataSet;
    public BlogDal()
    {
    conn = new SqlConnection();
    cmd = new SqlCommand();
    conn.ConnectionString = ConfigurationManager.ConnectionStrings["saCS"].ConnectionString;
    cmd.Connection = conn;
    }


    FInally execute the stored procedure or retrive data from stored procedure, etc.

    Hope it is clear.
     
    Naina S, Dec 4, 2014 IP