从Web应用程序连接到SQL Server 2008数据库 [英] Connect to a sql server 2008 database from a web application

查看:368
本文介绍了从Web应用程序连接到SQL Server 2008数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我想创建一个简单的Web应用程序来学习asp.net。

我正在尝试练习同时使用sql server 2008并将应用程序与数据库连接。



我的问题是如何使用我的sql server管理工作室设置本地数据库?以及我如何将它与asp.net应用程序连接起来?

我在网上看到了很多教程,但是当我尝试它们时我失败了,我有很多错误而且我是新的sql server和asp.net,我无法解决它们中的任何一个。



当我试图连接到数据库时,我收到以下错误从代码:

用户登录失败''''



当我尝试设置数据库登录时出现以下错误权限:



标题:Microsoft SQL Server管理工作室

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



用户dbo失败。 (Microsoft.SqlServer.Smo)



如需帮助,请单击: 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



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

附加信息:



执行Transact-SQL语句或批处理时发生异常。 (Microsoft.SqlServer.ConnectionInfo)



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



无法改变用户''dbo''。 (Microsoft SQL Server,错误:15150)



如需帮助,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.5000& EvtSrc = MSSQLServer& EvtID = 15150& LinkId = 20476



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

按钮:



OK

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



有谁知道一个很好的教程我一步一步?



谢谢

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

推荐答案

为了连接到数据库,你需要使用 SqlConnection [ ^ ](看看示例最后)。



要获得正确的连接字符串,请访问 http://www.connectionstrings.com/sql-server-2008 [ ^ ]



使用本地Sql Server实例时,您可以定义计算机的名称,也可以使用它来引用它。 (点)这是连接字符串中本地计算机的快捷方式。



不确定为什么要尝试更改任何用户。当您连接到数据库时,您要么使用Sql Server用户身份验证,这意味着您使用密码定义用户名以连接到数据库或您使用Windows身份验证,这再次意味着您的当前凭据将用于连接。



如果您使用Windows身份验证,请注意IIS使用的凭据用于连接。例如,看看在IIS 7.0上为ASP.NET网站设置SQL Server 2008 [ ^ ]
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[^]


http://blog.sqlauthority.com/2008/11/02/sql-server-fix-error-login-failed-for-user-username-the-user-is-not-associated -with-a-trusted-sql-server-connection / [ ^ ] br />




请参考以上链接。
http://blog.sqlauthority.com/2008/11/02/sql-server-fix-error-login-failed-for-user-username-the-user-is-not-associated-with-a-trusted-sql-server-connection/[^]


Please refer above link.


这篇关于从Web应用程序连接到SQL Server 2008数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆