连接字符串:connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Huoche.mdf;Integrated Security=True;User=sa;Password=123456;User Instance=True"
按道理我程序放在路径:C:\USERS\梦成\DESKTOP\201075实训\火车票订购实训改动版\火车票订购\火车票订购\火车票订购 
我发布在:D:\Train下面
附加的数据库名字却变成:C:\USERS\梦成\DESKTOP\201075实训\火车票订购实训改动版\火车票订购\火车票订购\火车票订购\APP_DATA\HUOCHE.MDF
百思不得其解,请大家帮帮忙

解决方案 »

  1.   


    出现这个错误的原因是什么啊???????????
    Exception Details: System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
      

  2.   

    Server Error in '/' Application.
    --------------------------------------------------------------------------------Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed. 
    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: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.Source Error: 
    Line 64: 
    Line 65:                 SqlConnection conn = new SqlConnection(sqlConnString);
    Line 66:                 conn.Open();
    Line 67:                 SqlCommand omd = new SqlCommand("", conn);
    Line 68:                 omd.CommandText = "SELECT * FROM 学生 WHERE 姓名='" + Username.Text + "'";
     Source File: C:\Users\梦成\Desktop\201075实训\火车票订购实训改动版\火车票订购\火车票订购\火车票订购\Default.aspx.cs    Line: 66 Stack Trace: 
    [SqlException (0x80131904): Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009598
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +5023255
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
       System.Data.SqlClient.SqlConnection.Open() +125
       火车票订购.Default.Button1_Click(Object sender, EventArgs e) in C:\Users\梦成\Desktop\201075实训\火车票订购实训改动版\火车票订购\火车票订购\火车票订购\Default.aspx.cs:66
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 
      

  3.   

    c#在字符串里要使用路径时,要加@string s=@"C:\USERS\梦成\DESKTOP\201075实训\火车票订购实训改动版\火车票订购\火车票订购\火车票订购 ";