Skip to content
iTecNote
  • Python
  • Javascript
  • PHP
  • Java
  • Android
  • iOS
  • jQuery
  • MySQL

How to connect a Visual Studio 2010 website to SQL Server 2005

asp.netc#-2.0login-controlsql-server-2005visual-studio-2010

I need to connect Visual Studio 2010 website to SQL Server 2005. My web site is ASP.NET using C#,
on the .NET Framework 2.0

I googled it for hours and every site i entered the information didn't seemed relevant.

Maybe I just don't understand.

I would appreciate if someone showed me from where to begin.

For example: I created a login form using login control from the toolbox but don't know how to continue from here, how do I get the password and username from the database?

Best Solution

To create a connection string follow my-steps:

  1. First drag a sqldatasource to a .aspx page
  2. Go to design part of that .aspx page
  3. Then mouse over on the sqldatasource, there you will find a option like "configure datasource".just click on that.
  4. It will give you popup, there you should give your db credential and select a db
  5. click next and select one table(whatever it may be) and write some query or select some column VS offer to you and click next
  6. NOW IT WILL ASK, WHETHER YOU WANT SAVE THIS CONNECTION SETTINGS.Here you can give the connection string name and click ok.(now you can delete that sqldatasource)
  7. now go to web.config and see the connection configuration.

    If you want to use registered users and logins in your application, Use Asp.net membership.For more Info Use Membership in ASP.NET 2.0

Related Solutions

Sql – Add a column with a default value to an existing table in SQL Server

Syntax:

ALTER TABLE {TABLENAME} 
ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} 
CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}
WITH VALUES

Example:

ALTER TABLE SomeTable
        ADD SomeCol Bit NULL --Or NOT NULL.
 CONSTRAINT D_SomeTable_SomeCol --When Omitted a Default-Constraint Name is autogenerated.
    DEFAULT (0)--Optional Default-Constraint.
WITH VALUES --Add if Column is Nullable and you want the Default Value for Existing Records.

Notes:

Optional Constraint Name:
If you leave out CONSTRAINT D_SomeTable_SomeCol then SQL Server will autogenerate
    a Default-Contraint with a funny Name like: DF__SomeTa__SomeC__4FB7FEF6

Optional With-Values Statement:
The WITH VALUES is only needed when your Column is Nullable
    and you want the Default Value used for Existing Records.
If your Column is NOT NULL, then it will automatically use the Default Value
    for all Existing Records, whether you specify WITH VALUES or not.

How Inserts work with a Default-Constraint:
If you insert a Record into SomeTable and do not Specify SomeCol's value, then it will Default to 0.
If you insert a Record and Specify SomeCol's value as NULL (and your column allows nulls),
    then the Default-Constraint will not be used and NULL will be inserted as the Value.

Notes were based on everyone's great feedback below.
Special Thanks to:
    @Yatrix, @WalterStabosz, @YahooSerious, and @StackMan for their Comments.

Sql-server – Check if table exists in SQL Server

For queries like this it is always best to use an INFORMATION_SCHEMA view. These views are (mostly) standard across many different databases and rarely change from version to version.

To check if a table exists use:

IF (EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'TheSchema' 
                 AND  TABLE_NAME = 'TheTable'))
BEGIN
    --Do Stuff
END
Related Question
  • Sql – How to do an UPDATE statement with JOIN in SQL Server
  • C# – The breakpoint will not currently be hit. No symbols have been loaded for this document in a Silverlight application
  • C++ – How to use Boost in Visual Studio 2010
  • Visual Studio 2010: Projectitem unavailable
  • C# – Writing to output window of Visual Studio
  • C# – ASP.NET 5 MVC: unable to connect to web server ‘IIS Express’