Your name or email adress:
Do you already have an account?
Forgot your password?
  • Log in or Sign up

    Results 1 to 2 of 2
    1. #1
      Tagger First Class31 days registered25000 Experience Points
      Frequent Poster
      CoderX's Avatar
      Senior Member
      Join Date
      Oct 2016
      Points: 44,533, Level: 100
      Points: 44,533, Level: 100
      Level completed: 0%,
      Required for next Level: 0
      Level completed: 0%, Required for next Level: 0
      Overall activity: 99.9%
      Overall activity: 99.9%

      Connecting to a SQL database from ASP .NET I

      This tutorial (divided in two parts) will show you how to connect from an ASP .NET web application to a SQL database using SQL authentication. To accomplish this you need to follow a series of steps, first to change some of the settings of SQL Server 2000 and create a database and a user and then to actually connect to the database using ASP .NET with Visual Studio .NET.

      I suppose you're going to use the MSDE 2000 (Microsoft SQL Server 2000 Desktop Engine) - the free version of the database.

      First set up the database using the tutorial named 'Setting up MS SQL Server 2000'.

      Authentication Mode

      There are two possible authentication modes for MSDE:
      Windows Integrated and SQL Login. By default, MSDE is using Windows Integrated authentication.

      But if you create some website that you are preparing to upload to a webhost, you'll probably want to prepare it for
      SQL Login.

      Because MSDE 2000 (being free) doesn't have a user interface we need to change the authentication mode from the registry.

      Navigate using
      regedit to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\ MSSQLServer and double-click the LoginMode key. The value that LoginMode currently holds is probably 1 which means Windows Integrated. We change this to the value 2, which means Mixed Mode:

      Connecting to a SQL database from ASP .NET I

      Creating a new database

      Microsoft SQL Web Data Administrator (if you don't have it installed read this) - if you don't start it from the Start Menu you can usually find it at https://localhost/webadmin.

      First login using the
      Windows Integrated option, and also leave the other fields with the default values - just press the Loginbutton.

      After you are logged in, the
      Databases page shows up. It displays the available databases:

      Connecting to a SQL database from ASP .NET I

      Click on the
      Create new database link. You are asked to enter a name for the new database - enter 'MyDB' (without the quotes) and click Create.

      After the database is created you can see that no there are no tables to be displayed. So let's create one by using the
      Create new table link. When you are prompted to enter a new name for the table choose 'MyLinks' and click Create. The table is created and we are redirected to the Edit Column page where we can add a new column to the table, and we will.

      In the
      Column Name field enter 'Title'. Leave the Data Type to char, but change the Length property to '64' (characters). Leave the rest unchanged and press Add.

      The new column was created but let's create another one.

      Again click on the
      Create new column link and set the Column Name to 'URL' and the length field to '128'. Press submit and the second column is created:

      Connecting to a SQL database from ASP .NET I

      From the left side menu choose
      Query cause we're going to store a value.

      Run the following query there:

      INSERT INTO MyLinks (Title, URL) VALUES ('Geekpedia', '')

      Now that you are still at the Query page, run the following query to see the inserted rows:

      SELECT * FROM MyLinks

      Look at the bottom of the page and you'll see the row we just inserted:

      Connecting to a SQL database from ASP .NET I

      Creating a new user

      Connecting to a SQL database from ASP .NET INow you're going to create a new user with a password, that we'll use to connect to the database from the web application. Again, we'll accomplish using
      Microsoft SQL Web Data Administrator.

      From the left menu choose the
      Security link This will bring you to the Security page where you'll encounter two icons. Choose Logins. The Logins page shows the curent accounts that are allowed to use access the database along with their privileges.

      Above the table, there is a
      Create new login link. Click it and from the page that shows up choose Sql Login. For the login name I recommend using aspnet and for the password... well, it's your choice. After you complete the fields and click the Create Login link, the Editing login aspnet page shows up. Go to Database Access section and check the checkbox next to MyDB:

      Connecting to a SQL database from ASP .NET I

      Save changes and you can now see the result - the login has been added:

      Connecting to a SQL database from ASP .NET I

      There's one more thing. We need to set the privileges for this user. So on the left menu choose
      Databases, from the list of the databases that showed up click MyDB, of course. The left menu now has some other new items:

      Connecting to a SQL database from ASP .NET IChoose
      Users and now a page shows up with a table that contains the users that have access to this database. Obviously, we are interested in aspnet, so click the Edit link next to it. The roles for this user show up with a checkbox next to them. As we currently don't want to waste time, check them all, except db_denydatareader and db_denydatawriter. Save the settings with the Save User button.

      We're done.

      Now you can test it. Logout (there's a small X button in the upper-right corner of the page that will log you out) and at the login page choose
      SQL Login instead of Windows Integrated and enter the username (aspnet) and the password you choosed earlier.

      That's it, the database is set up, now we only have to connect to it from the ASP .NET web application. This is covered in part II of the tutorial:

    2. #2
      250 Experience Points3 months registered
      iori117's Avatar
      Join Date
      Mar 2017
      Points: 350, Level: 6
      Points: 350, Level: 6
      Level completed: 50%,
      Required for next Level: 50
      Level completed: 50%, Required for next Level: 50
      Overall activity: 0%
      Overall activity: 0%
      Thanks brother

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts

    LeakNinja (LN) Contact Details:
    Main address: 4407 Oakwood Avenue 87937 Paris, France ,
    Tel:( 21 2) 645-8417 , Fax:( 33 1) 645-34517 ,