Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to create a simple web application to learn asp.net.
I'm trying to practice a sql server 2008 in the same time and connect the application with the database.

My question is how can i set a local database with my sql server management studio? and how i can connect it with the asp.net application?
I saw a lot of tutorials on the net but i failed when i tried them, i had lot of errors and i'm new with sql server and asp.net and i could not solve any of them.

I'm getting the following error when i'm trying to connect to the database from the code:
Login failed for user ''

And the following error when i try to set the database log in and permissions:

TITLE: Microsoft SQL Server Management Studio
------------------------------

Alter failed for User 'dbo'. (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1447.4+((KJ_RTM).100213-0103+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Alter+User&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

Cannot alter the user 'dbo'. (Microsoft SQL Server, Error: 15150)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.5000&EvtSrc=MSSQLServer&EvtID=15150&LinkId=20476

------------------------------
BUTTONS:

OK
------------------------------

Do anyone know a good tutorial that leads me step by step?

Thanks
Posted
Updated 4-Jan-13 8:57am
v2

In order to connect to the database, you need to use a SqlConnection[^] (have a look at the example in the end).

To get the connection string right, visit http://www.connectionstrings.com/sql-server-2008[^]

When you use local Sql Server instance, you can define a name of the computer or you can refer it using . (dot) which is a shortcut for local computer in connection strings.

Not sure why you're trying to alter any user. When you connect to the database, you either use Sql Server user authentication which means that you define a user name with a password in order to connect to the database or you use windows authentication which again means that your current credentials will be used for the connection.

If you use Windows authentication, notice that the credentials that are used with IIS are used for the connection. For example, have a look at Setting up SQL Server 2008 for an ASP.NET website on IIS 7.0[^]
 
Share this answer
 
Comments
Espen Harlinn 6-Jan-13 9:14am    
5'ed!
Wendelius 6-Jan-13 10:56am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900