Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用ASP.NET连接到MSSQL Express_C#_Asp.net_.net_Sql Server - Fatal编程技术网

C# 如何使用ASP.NET连接到MSSQL Express

C# 如何使用ASP.NET连接到MSSQL Express,c#,asp.net,.net,sql-server,C#,Asp.net,.net,Sql Server,我有一个从VisualStudio2010创建的应用程序,还有一个专用服务器。服务器的操作系统是windows server 2003。我的web应用程序正在Visual Studio的localhost和我的IIS localhost上运行。但当我把它发布到服务器时,它给了我这个错误 Login failed for user 'sa'. Description: An unhandled exception occurred during the execution of the cu

我有一个从VisualStudio2010创建的应用程序,还有一个专用服务器。服务器的操作系统是windows server 2003。我的web应用程序正在Visual Studio的localhost和我的IIS localhost上运行。但当我把它发布到服务器时,它给了我这个错误

Login failed for user 'sa'. 


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: Login failed for user 'sa'.

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 (0x80131904): Login failed for user 'sa'.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5066458
   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) +185
   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
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +94
   BerksanWebSite.Default2.Page_Load(Object sender, EventArgs e) in C:\Users\tekizer\documents\visual studio 2010\Projects\BerksanWebSite\BerksanWebSite\Default2.aspx.cs:94
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1022
这是我在web.config文件中的connectionstring标记

 <connectionStrings>
    <add name="websitesiConnectionString" connectionString="Server=xx.xxx.xxx.xxx; Database=websitesi;User ID=xxxx;Password=xxxxxx;"/>

  </connectionStrings>
我在我的c#页面上调用这个,以连接专用服务器上的数据库

SqlConnection baglanti = new SqlConnection(berksanproje.connectionstring);
if(baglanti.State!=ConnectionState.Open)
{
baglanti.Open();
}
在我的专用服务器的ASP.NET web应用程序属性中 ASP.NET版本4.0.30319 单击“编辑配置”并单击“常规”选项卡时,会显示:

LocalSqlServer : Data Source=.\SQLEXPRESS;Initial Catalog=berksanwebsitesi;Integrated Security=True;

websitesiConnectionString : Server=xx.xxx.xxx.xxx; Database=websitesi;User ID=xxxx;Password=xxxxxx;
我可以通过MSSQL通过远程连接从我的计算机连接到我的数据库。但我发布后无法连接到我的aspx页面。有没有办法将我的数据库连接到asp.net


注意:我不会在任何地方编写与用户sa连接的代码。我不使用它。

您似乎必须使用windows身份验证,或者您没有
sa
用户

我假设您使用windows身份验证进行连接,因此更改所有连接字符串,如下所示:

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

有关更多详细信息,请参阅此页,您的案例可能不需要windows身份验证,因此请检查链接并找到适合您的连接字符串

我已将windows server 2008安装到我的专用服务器。然后,在使用Management studio安装.NET Framework 4.0和MSSQL Server 2008 R2 Express后,我的系统开始工作。

看起来您的ASP页面试图通过sql Server身份验证(用户名+密码)进行连接,而您的计算机则通过windows身份验证(集成安全)进行连接。那么,SQL Server是否配置为能够使用SQL Server身份验证(即“混合模式”)?——另外,如果您有一个命名实例,可能需要指定(
Server=xx.xxx.xxx.xx\InstanceName
)是。我可以用IP连接我的电脑。1433端口是否打开?SQL server是否在服务中运行?是-我写在上面-。它通过VisualStudio的本地主机在我的计算机上工作。数据库位于专用服务器上。您是否有Sql server“sa”用户?连接到sql server实例时,是否使用windows身份验证?我有sa用户。但我没有在任何地方使用它。当我尝试使用sa时,那里没有任何变化。我不知道该怎么解决这个问题problem@enderariçu是否可以使用sql server management studio通过用户
sa
连接到您的sql server?是的,我可以使用用户sai建议与sql server management studio连接,以替换所有连接字符串,如
数据源=myserver地址;初始目录=网站i;用户ID=sa;密码=你的密码。我假设你的密码就是你的密码
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;