Online Shopping : Computers : Programming : Languages : Asp : Asp.net : Database backed sites : Microsoft SQL Server

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 41 people (68%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

ASP.NET: Visual Basic: Database: Microsoft: SQL server: How to connect to a database?

Mar 18th, 2009 07:42
engatoo engatoo, alex martin, John Martin, Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 12 December 2003 - 23:38 pm -------------------
ASP.NET: Visual Basic: Database: Microsoft: SQL server: How to connect 
to a database?
---
Steps: Overview:
 1. -Setup a database connection
 2. -Open the database connection
 3. -Fill a dataset with the desired data
 4. -Set up a dataview to display data
 5. -Bind a server control to the dataview via data binding
---
---
Steps: Worked out:
 1. -Start a new Visual Basic Windows or ASP.NET application.
 2. -Add a datagrid control to the form
    (to display records from your database)
    1. -on the left click on the vertical 'toolbox',
    2. -click button 'Web Forms'
    3. -double click button 'DataGrid'
 3. Add an OleDbDataAdapter control to the form
    (to connect to your database)
    1. -on the left click on the vertical 'Toolbox'
    2. -click button 'Data'
    3. -double click button 'OleDbDataAdapter'
 4. -This will start a 'Data Adapter Configuration'
     wizard
 5. -click button 'Next'
 6. -Select an existing connection from the list,
     otherwise click button 'New connection'
     (if there should be a blank entry in
      'Which data connection should the data adapter use')
     1. -This will open a window 'Data Link properties'
     2. -choose a (Microsoft SQL) server name
         e.g. DELLI8500
      You should supply the same server name as the SQL server that is
      running (you can choose this name while
      installing the
      Microsoft SQL server database,
      or ask the administrator of the computer
      on which the Microsoft SQL server runs on the
      network)
      To see this, put the mouse on the taskbar over the Microsoft SQL
      server icon, and there you see e.g.
      \\DELLI8500 - MS SQL Server
      (adapt this name to your conditions)
     3. -enable radio button 'Use Windows NT Integrated security'
        (or otherwise when enabling 'Use a specific user name and 
password',
         supply the login name + password, if you did choose this
         option while setting up Microsoft SQL server)
     4. -select the database on the server.
         A typical demonstration database for
         Microsoft SQL server is 'Northwind'
     5. -possibly click button 'Test Connection' to test
         (if successful, you see 'Test connection succeeded')
     6. -click button 'OK'
     7. -Select then this database in:
         'Which data connection should the data adapter use' select
         (e.g. DELLI8500.Northwind.dbo)
 7. -accept e.g. the default enabled radio button
     'Use SQL statements'
     Other possible options here are:
     o 'Create new stored procedures'
        (=specify a 'Select' statement and the wizard
        will generate new stored procedures to select,
        insert, update and delete records)
     o 'Use existing stored procedures'
        (=choose an existing stored procedure for each
          operation (select, insert, update and
          delete)
 8. -in window 'Data Adapter Configuration Wizard',
     you can (for example) type the following text:
      SELECT * FROM Products
 9. -click button 'Next'
10. -click button 'Finish'
11. -you will now see that 2 items are present
     under the 'Component1.vb [Design]' tab
     1. 'OleDbDataAdapter1'
     2. 'OleDbConnection1'
12. -possibly give the form focus,
     1. -select from menu option 'View'
     2. -select from list 'Designer'
13. -generate a dataset
     1. -select from menu option 'Data'
     2. -select from list 'Generate DataSet...'
     (Note:
      if you should select from the list 'View Dataset', and then click
      button 'Fill Dataset', you can see the result of your query
      (e.g. SELECT * FROM Products))
14. -a dialog box 'Generate Dataset' opens, and
     asks to choose a 'DataSet'
     1. I chose 'New'
     2. I chose to leave the default name 'DataSet1'
     3. I enabled checkbox 'Add this dataset to the designer'
     4. click button 'OK'
15. -you will now see that totally 3 items are present
     below
     1. 'OleDbConnection1'
     2. 'OleDbDataAdapter1'
     3. 'DataSet11'
     This 3 objects have the following function:
     1. Connection object
        This represents your database connection
     2. Data Adapter object.
        This uses a connection and a command to fill a DataSet with
        Records
     3. DataSet
        This represents a set of records that were requested using a
        command.
     The command I chose was here
      SELECT * FROM Products
     which asks for all records (*) from the Products table.
     To associate the set of records returned from our SQL query with
     the 'DataGrid' control you have to set the DataSource property.
     Establishing an association between a control and a database is
     referred to as binding a control to data.
     In the following steps you will have to bind the 'DataGrid'
     control to the 'DataSet'.
16. -set the 'DataSource' property of the 'datagrid' control
     1. -make sure the 'Properties' window is visible
         1. -select from menu option 'View'
         2. -select from list 'Properties Window'
     2. -click once on the 'datagrid' control on the form
     3. -In the 'Properties' window in the right pane:
         1. set the 'DataSource' property to
            1. If you are creating a Visual Basic windows application,
               select:
                DataSet11.Products
            2. If you are creating a Visual Basic ASP.NET
               application, select:
                DataSet11
17. -create a connection and fill a dataset
     1. -select from menu option 'View'
     2. -select from list 'Designer'
     3. -double click on the form to open the 'Code Editor' window,
         focused on the Form1_Load event handler.
     4. -type the following text:
         1. If you are creating a Visual Basic windows application,
            type:
             OleDbDataAdapter1.Fill( Me.DataSet11 )
         2. If you are creating a Visual Basic ASP.NET
            application, select, type:
             OleDbDataAdapter1.Fill(Me.DataSet11)
             DataGrid1.DataBind()
18. Run this application
    1. -press <F5>
        or
        select from menu option 'Debug'
        then select from list 'Start'
    4. -now the 'DataGrid' control should display all the records from
        the Products table
    Navigation, modification, addition, and deletion of records are
    possible with the DataGrid control.
19. Troubleshooting
    1. If you get the error
       'Login failed for user 'Machinename\ASPNET'
       then a general solution is to add this
       'Machinename\ASPNET' user to that
        Microsoft SQL server database.
        (so add e.g. a user to the database 'Northwind')
    ---
    2. If you run the application and you get a blank screen:
       Try one or more of the following:
       1. Check if you did bind your datasource to the
          datagrid control
          1. -click on the datagrid control on the form
          2. -in the window 'Properties' goto property
              'datasource' and select from the list
              'datasource'
               1. If you are creating a Visual Basic windows
                  application, select:
                   DataSet11.Products
               2. If you are creating a Visual Basic ASP.NET
                  application, select:
                   DataSet11
       2. Try to check if your query produced any data
          1. -select from menu option 'Data'
          2. -select from list 'Preview data...'
          3. -click button 'Fill Data'
          4. -you should now see some data filled in
              in your table
       3. If creating for ASP.NET, check if you indeed typed the text:
             DataGrid1.DataBind()
---
---
Book: see also:
[book: Utley, Craig - a programmer's introduction to Visual Basic.NET -
 ISBN 0-672-32203-X - p. 106 'Accessing a database from a Windows 
Application']
---
---
Internet: see also:
---
Database: Microsoft: SQL server: User: Add: How to add a user to a 
database? [Northwind]
http://www.faqts.com/knowledge_base/view.phtml/aid/27359/fid/147
---
Database: Microsoft SQL server: Error 'Login failed for user '<your 
computer name>\ASPNET'
http://www.faqts.com/knowledge_base/view.phtml/aid/27428/fid/1601
.freemusicpoint.com/
http://dl3.com/link/category/voice
http://dl3.com/link/category/chat
http://dl3.com/link/category/song
http://dl3.com/link
http://www.dl3.com/smiles
http://www.dl3.com/cards
http://games.dl3.com
http://www.chataluae.com
http://www.dl3.com/vb/index.php
http://www.dl3.com/vb
http://www.dl3.com/vb
http://www.dl3.com
http://www.stop10.com
http://topics.ll6.com
http://topics.ll6.com
http://www.stop10.com
http://www.ll6.com/java.shtml
http://dlel.ll6.com/c21.html
http://dlel.ll6.com/c20.html
http://dlel.ll6.com/c19.html
http://dlel.ll6.com/c18.html
http://dlel.ll6.com/c17.html
http://dlel.ll6.com/categories.xml
http://dlel.ll6.com/sitemap.xml
http://dlel.ll6.com/c10.html
http://dlel.ll6.com/c9.html
http://dlel.ll6.com/c8.html
http://dlel.ll6.com/c7.html
http://dlel.ll6.com/c6.html
http://dlel.ll6.com/c5.html
http://dlel.ll6.com/c4.html
http://dlel.ll6.com/c3.html
http://dlel.ll6.com/c2.html
http://dlel.ll6.com/c10.html
http://dlel.ll6.com/c16.html
http://dlel.ll6.com/c15.html
http://dlel.ll6.com/c14.html
http://dlel.ll6.com/c13.html
http://dlel.ll6.com/c12.html
http://dlel.ll6.com/c11.html
http://voice.ll6.com
http://www.ll6.com
http://vb.ll6.com/forumdisplay.php?f=50
http://vb.ll6.com/forumdisplay.php?f=41
http://vb.ll6.com/forumdisplay.php?f=35
http://vb.ll6.com/forumdisplay.php?f=34
http://vb.ll6.com/forumdisplay.php?f=33
http://vb.ll6.com/forumdisplay.php?f=32
http://vb.ll6.com/forumdisplay.php?f=31
http://vb.ll6.com/forumdisplay.php?f=30
http://vb.ll6.com/forumdisplay.php?f=29
http://vb.ll6.com/forumdisplay.php?f=28
http://vb.ll6.com/forumdisplay.php?f=27
http://vb.ll6.com/forumdisplay.php?f=26
http://vb.ll6.com/forumdisplay.php?f=25
http://vb.ll6.com/forumdisplay.php?f=24
http://vb.ll6.com/forumdisplay.php?f=23
http://vb.ll6.com/forumdisplay.php?f=22
http://vb.ll6.com/forumdisplay.php?f=21
http://vb.ll6.com/forumdisplay.php?f=20
http://vb.ll6.com/forumdisplay.php?f=19
http://vb.ll6.com/forumdisplay.php?f=18
http://vb.ll6.com/forumdisplay.php?f=17
http://vb.ll6.com/forumdisplay.php?f=5
http://vb.ll6.com/forumdisplay.php?f=6
http://vb.ll6.com/forumdisplay.php?f=10
http://vb.ll6.com/forumdisplay.php?f=4
http://vb.ll6.com/index.php
http://ll6.com
http://www.alshalah.com
http://www.alshalah.com/chat1420.html
http://www.alshalah.com/music22.html
http://www.alshalah.com/music21.html
http://www.alshalah.com/chat1355.html
http://www.alshalah.com/chat1507.html
http://www.alshalah.com/download7.html
http://www.alshalah.com/download7.html
http://www.alshalah.com/chat1337.html
http://www.alshalah.com/chat100.html
http://www.alshalah.com/music12.html
http://www.alshalah.com/music12.html
http://www.alshalah.com/download5.html
http://www.alshalah.com/music23.html
http://www.alshalah.com/chat1339.html
http://www.alshalah.com/chat103.html
http://www.alshalah.com/music15.html
http://www.alshalah.com/chat1528.html
http://www.alshalah.com/chat1359.html
http://www.alshalah.com/chat1519.html
http://www.alshalah.com/chat1422.html
http://www.alshalah.com/music4.html
http://www.alshalah.com/chat101.html
http://www.alshalah.com/chat106.html
http://www.alshalah.com/chat102.html
http://www.alshalah.com/chat1166.html
http://www.alshalah.com/vote.php
http://www.alshalah.com/visit.php
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2820.html
http://www.alshalah.com/chat2820.html
http://www.alshalah.com/chat2819.html
http://www.alshalah.com/chat2819.html
http://www.alshalah.com/chat2818.html
http://www.alshalah.com/chat2818.html
http://www.alshalah.com/chat2817.html
http://www.alshalah.com/chat2817.html
http://www.alshalah.com/chat2816.html
http://www.alshalah.com/chat2816.html
http://www.alshalah.com/chat2815.html
http://www.alshalah.com/chat2815.html
http://www.alshalah.com/chat2814.html
http://www.alshalah.com/chat2814.html
http://www.alshalah.com/chat2813.html
http://www.alshalah.com/chat2813.html
http://www.alshalah.com/chat2812.html
http://www.alshalah.com/chat2812.html
http://www.alshalah.com/chat2813.html
http://www.alshalah.com/chat2811.html
http://www.alshalah.com/chat2811.html
http://www.alshalah.com/chat2810.html
http://www.alshalah.com/chat2810.html
http://www.alshalah.com/chat2809.html
http://www.alshalah.com/chat2809.html
http://www.alshalah.com/chat2808.html
http://www.alshalah.com/chat2808.html
http://www.alshalah.com/chat2807.html
http://www.alshalah.com/chat2807.html
http://www.alshalah.com/chat2806.html
http://www.alshalah.com/chat2806.html
http://www.alshalah.com/chat2805.html
http://www.alshalah.com/chat2804.html
http://www.alshalah.com/chat2803.html
http://www.alshalah.com/chat2803.html
http://www.alshalah.com/chat2802.html
http://www.alshalah.com/voice
http://www.alshalah.com/vb
http://www.alshalah.com/
http://www.alshalah.com/download3.html
http://www.alshalah.com/music6.html
http://www.alshalah.com/music6.html
http://www.alshalah.com/music5.html
http://www.alshalah.com/music5.html
http://www.alshalah.com/music4.html
http://www.alshalah.com/music4.html
http://www.alshalah.com/music3.html
http://www.alshalah.com/music3.html
http://www.alshalah.com/music22.html
http://www.alshalah.com/music21.html
http://www.alshalah.com/music19.html
http://www.alshalah.com/music18.html
http://www.alshalah.com/vb/sex202
http://www.alshalah.com/vb/sex205
http://www.alshalah.com/vb/sitemap
http://www.alshalah.com/vb/sitemap/f-183.html
http://www.alshalah.com/chat101.html
http://www.alshalah.com/chat101.html
http://www.alshalah.com/vb/picturet38947.html
http://www.alshalah.com/vb/picturet25902.html
http://www.alshalah.com/chat2801.html
http://www.alshalah.com/chat2800.html
http://www.alshalah.com/chat2799.html
http://www.alshalah.com/download10.html
http://www.alshalah.com/chat259.html
http://www.alshalah.com/vb/picturet939.html
http://www.alshalah.com/vb/picturet7317.html
http://www.alshalah.com/chat102.html
http://www.alshalah.com/chat312.html
http://www.alshalah.com/vb/picturet706.html
http://www.alshalah.com/vb/picturet22974-2.html
http://www.alshalah.com/vb/picturet26805.html
http://www.alshalah.com/chat601.html
http://www.alshalah.com/vb/picturet29167.html
http://www.alshalah.com/vb/picturet21358.html
http://www.alshalah.com/vb/picturet42591.html
http://www.alshalah.com/vb/picturet10141.html
http://www.alshalah.com/chat960.html
http://www.alshalah.com/chat658.html
http://www.alshalah.com/chat102.html
http://www.alshalah.com/chat1166.html
http://www.alshalah.com/vb/picturet34614.html
http://www.alshalah.com/chat2470.html
http://www.alshalah.com/vb/picturet44915.html
http://www.alshalah.com/download5.html
http://www.alshalah.com/chat2408.html
http://www.alshalah.com/chat2408.html
http://www.alshalah.com/vb/picturet24559.html
http://www.alshalah.com/music11.html
http://www.alshalah.com/vb/picturet40695.html
http://www.alshalah.com/vb/picturet1067.html
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.dir.3rabstarz.com/
http://www.up.3rabstarz.com
http://www.3rabstarz.com/vb/forumdisplay.php?f=5
http://www.3rabstarz.com/vb/forumdisplay.php?f=116
http://www.3rabstarz.com/vb/forumdisplay.php?f=66
http://www.3rabstarz.com/vb/forumdisplay.php?f=78
http://www.3rabstarz.com/vb/forumdisplay.php?f=147
http://www.3rabstarz.com/vb/forumdisplay.php?f=2
http://www.3rabstarz.com/vb/forumdisplay.php?f=31
http://www.3rabstarz.com/vb/forumdisplay.php?f=136
http://www.3rabstarz.com/vb/forumdisplay.php?f=34
http://www.3rabstarz.com/vb/forumdisplay.php?f=89
http://www.3rabstarz.com/vb/forumdisplay.php?f=26
http://www.3rabstarz.com/vb/forumdisplay.php?f=72
http://www.3rabstarz.com/vb/forumdisplay.php?f=73
http://www.3rabstarz.com/vb/forumdisplay.php?f=149
http://www.3rabstarz.com/vb/forumdisplay.php?f=150
http://www.3rabstarz.com/vb/forumdisplay.php?f=151
http://www.3rabstarz.com/vb/forumdisplay.php?f=152
http://www.3rabstarz.com/vb/forumdisplay.php?f=67
http://www.3rabstarz.com/vb/forumdisplay.php?f=3
http://www.3rabstarz.com/vb/forumdisplay.php?f=37
http://www.3rabstarz.com/vb/forumdisplay.php?f=115
http://www.3rabstarz.com/vb/forumdisplay.php?f=76
http://www.3rabstarz.com/vb/forumdisplay.php?f=77
http://www.3rabstarz.com/vb/forumdisplay.php?f=36
http://www.3rabstarz.com/vb/forumdisplay.php?f=153
http://www.3rabstarz.com/vb/forumdisplay.php?f=122
http://www.3rabstarz.com/vb/forumdisplay.php?f=118
http://www.3rabstarz.com/vb/forumdisplay.php?f=119
http://www.3rabstarz.com/vb/forumdisplay.php?f=120
http://www.3rabstarz.com/vb/forumdisplay.php?f=121
http://www.3rabstarz.com/vb/forumdisplay.php?f=35
http://www.3rabstarz.com/vb/forumdisplay.php?f=65
http://www.3rabstarz.com/vb/forumdisplay.php?f=7
http://www.3rabstarz.com/vb/forumdisplay.php?f=9
http://www.3rabstarz.com/vb/forumdisplay.php?f=11
http://www.3rabstarz.com/vb/forumdisplay.php?f=142
http://www.3rabstarz.com/vb/forumdisplay.php?f=143
http://www.3rabstarz.com/vb/forumdisplay.php?f=146
http://www.3rabstarz.com/vb/forumdisplay.php?f=140
http://www.3rabstarz.com/vb/forumdisplay.php?f=137
http://www.3rabstarz.com/vb/forumdisplay.php?f=114
http://www.3rabstarz.com/vb/forumdisplay.php?f=117
http://www.3rabstarz.com/vb/forumdisplay.php?f=113
http://www.3rabstarz.com/vb/forumdisplay.php?f=51
http://www.3rabstarz.com/vb/forumdisplay.php?f=84
http://www.3rabstarz.com/vb/forumdisplay.php?f=138
http://www.3rabstarz.com/vb/forumdisplay.php?f=139
http://www.3rabstarz.com/vb/forumdisplay.php?f=15
http://www.3rabstarz.com/vb/forumdisplay.php?f=130
http://www.3rabstarz.com/vb/forumdisplay.php?f=97
http://www.3rabstarz.com/vb/forumdisplay.php?f=102
http://www.3rabstarz.com/vb/forumdisplay.php?f=101
http://www.3rabstarz.com/vb/forumdisplay.php?f=104
http://www.3rabstarz.com/vb/forumdisplay.php?f=131
http://www.3rabstarz.com/vb/forumdisplay.php?f=103
http://www.3rabstarz.com/vb/forumdisplay.php?f=99
http://www.3rabstarz.com/vb/forumdisplay.php?f=59
http://www.3rabstarz.com/vb/forumdisplay.php?f=60
http://www.3rabstarz.com/vb/forumdisplay.php?f=39
http://www.3rabstarz.com/vb/forumdisplay.php?f=40
http://www.3rabstarz.com/vb/forumdisplay.php?f=42
http://www.3rabstarz.com/vb/forumdisplay.php?f=4
http://www.3rabstarz.com/vb/forumdisplay.php?f=1
http://www.3rabstarz.com/vb/forumdisplay.php?f=88
http://www.3rabstarz.com/vb/forumdisplay.php?f=148
http://www.3rabstarz.com/vb/forumdisplay.php?f=62
http://www.3rabstarz.com/vb/forumdisplay.php?f=63
http://www.3rabstarz.com/vb/forumdisplay.php?f=64
http://www.3rabstarz.com/vb/forumdisplay.php?f=6
http://www.3rabstarz.com/vb/forumdisplay.php?f=12
http://www.3rabstarz.com/vb/forumdisplay.php?f=96
http://www.3rabstarz.com/vb/forumdisplay.php?f=58
http://www.3rabstarz.com/vb/forumdisplay.php?f=38