大虾,过来帮帮我吧,急

booro 2003-08-10 09:50:46
初次接触ASP。NET

一个问题:

使用SQL Server服务器 连接数据库出错


代码没有写错,SQL服务器名字也对, 我安装的是 SQL Server2002 个人专业版本
服务器自动运行 不过我对服务器没有任何设置
下面是我运行的代码:
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>

<html>
<head><title> WROX Beginning ASP.NET - Data - Data Table <br/>
Using Microsoft SQL Objects</title></head>

<body>
<h2>Display of Data in a Table (Grid) Using SQL Objects</h2>

Northwind Employees:
<asp:datagrid id="dgrEmployees" runat="server" />

<script language="vb" runat="server">
Sub Page_Load()

' First we will set up variables to hold two strings
Dim strSQL as string = "SELECT FirstName,LastName FROM Employees;"
Dim strConnection as String = "server=FDCGL;database=Northwind; User Id=sa;password=;"

Dim objDataSet As New DataSet()
Dim objConnection As New SqlConnection(strConnection)

'create a new DataAdapter using the connection object and select statement
Dim objDataAdapter As New SqlDataAdapter(strSQL, objConnection)

'fill the dataset with data from the DataAdapter object
objDataAdapter.Fill(objDataSet, "Employees")

'create a DataView object for the Employees table in the DataSet
Dim objDataView As New DataView(objDataSet.Tables("Employees"))

'assign the DataView object to the DataGrid control
dgrEmployees.DataSource = objDataView
dgrEmployees.DataBind() 'and bind (display) the data

End Sub
</script> </body> </html>


连接数据库出错

提示内容如下:


Server Error in '/BegASPNET' Application.
--------------------------------------------------------------------------------

用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:


[SqlException: 用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +472
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +44
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +36
ASP.DataTableBasicUsingSQLObjects_aspx.Page_Load() +106
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573


说明: 我的ASP。NET运行环境没有问题 一直都运行正常,我过去使用的数据驱动程序都是OLEDB ACCESS2003 ,第一次用SQL Server ,

...全文
85 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
michael3769 2003-08-10
  • 打赏
  • 举报
回复
数据库的登陆后令改为空
panyee 2003-08-10
  • 打赏
  • 举报
回复
"data source=FDCGL;initial catalog=Northwind;persist security info=False;user id=sa;password=;"
zhangzs8896 2003-08-10
  • 打赏
  • 举报
回复
混合模式登陆吗?不是的话就改一下吧

如果你用的是windows登陆模式:
"server=FDCGL;database=Northwind; Integrated Security=sspi"
如果是混合模式登陆,才应该是:
"server=FDCGL;database=Northwind; User Id=sa;password="
---------------------------------------------------------------
我发现你的Dim strConnection as String = "server=FDCGL;database=Northwind; User Id=sa;password=;"中也不大对。
==================》
Dim strConnection as String = "server=FDCGL;database=Northwind; User Id=sa;password="
暗石绿 2003-08-10
  • 打赏
  • 举报
回复
Dim strConnection as String = "server=FDCGL;database=Northwind; uid=sa;pwd=;"
panyee 2003-08-10
  • 打赏
  • 举报
回复
把数据库设置安全性改成windows和sql server都可以登录

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧