这个是异常提示:
未处理 System.Data.SqlClient.SqlException
  Message="无法打开登录 'dinner' 中请求的数据库。登录失败。\r\n用户 'sa' 登录失败。"
  Source=".Net SqlClient Data Provider"
  ErrorCode=-2146232060
  Class=11
  LineNumber=0
  Number=4060
  Procedure=""
  Server="."
  State=1
  StackTrace:
       在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       在 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
       在 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
       在 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
       在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
       在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
       在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
       在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
       在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
       在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
       在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
       在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
       在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
       在 System.Data.SqlClient.SqlConnection.Open()
       在 dinner.frmLogin.btnSubmit_Click(Object sender, EventArgs e) 位置 F:\dinner\dinner\frmLogin.cs:行号 48
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 dinner.Program.Main() 位置 F:\dinner\dinner\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

解决方案 »

  1.   

    提示已经很明白了,你的数据库是什么SQL2000吗?
      

  2.   

    前几天我也遇到的,后来我把,uid=sa;pwd=非空;就可以连上了,但是在创建数据库的时候要加个密码的
    Sqlconnection conn = "@server = "" ; database = dinner; uid = sa ; pwd = ;" ;
    就可以了吧
      

  3.   

    我在测试连接数据库的时候能够通过。
    pwd是为空啊。数据库是sql server2000.
    class DBConn
        {
            public static SqlConnection CyCon()
            {
                return new SqlConnection("server=.;database=dinner;uid=sa;pwd=");
                //return new SqlConnection("server=.;database=dinner;uid=sa;pwd=");
            }
        }