大虾,过来帮帮我吧,急
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 ,