这样一段代码写在网站的global.asax.cs文件里protected void Session_Start(Object sender, EventArgs e)
{
SqlConnection myConn=new SqlConnection("server=485C2381458E462;uid=sa;pwd=;database=teacher-student;");

string str1="select Grade,Term,CourseID,CourseName,LearnHours  from Teaching_plan";
SqlCommand SqlSele=new SqlCommand(str1,myConn);

                        myConn.Open();
SqlDataAdapter Adapter=new SqlDataAdapter();
Adapter.SelectCommand=SqlSele;
DataSet myDs=new DataSet();
Adapter.Fill(myDs,"Teaching_plan");
myConn.Close();
Application["TeachingTask"]=myDs;
}运行程序后出现:
Server Error in '/' Application.
--------------------------------------------------------------------------------SQL Server does not exist or access denied. 
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: SQL Server does not exist or access denied.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
[SqlException: SQL Server does not exist or access denied.]
   System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +474
   System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
   System.Data.SqlClient.SqlConnection.Open() +384
   WebApplication1.Global.Session_Start(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\Global.asax.cs:39
   System.Web.SessionState.SessionStateModule.CompleteAcquireState() +525
   System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +698
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +66
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +173 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 请问怎么回事啊?????在线等,可否QQ谈????

解决方案 »

  1.   

    SQL Server does not exist or access denied.
    连接字符串问题或者是Sql server没有启动.
      

  2.   

    SqlConnection myConn=new SqlConnection("server=485C2381458E462;uid=sa;pwd=;database=teacher-student;"); 
    修改这个试试,
    参考 
    http://www.connectionstrings.com/?carrier=sqlserver并确认在server *485C2381458E462*上的sql server服务开启的.
      

  3.   

    跟web。config文件里的这段有 没有关系?<sessionState 
                mode="InProc"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="data source=485C2381458E462;Trusted_Connection=yes"
                cookieless="false" 
                timeout="20" 
        />