timer数据库总显示连接不上服务器,asp.net 上传服务器后,MSSQL数据库连接问题

Server Errorin'/'Application.--------------------------------------------------------------------------------用户'test'登录失败。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack traceformore information about the error andwhereit originatedinthe code.

Exception Details: System.Data.SqlClient.SqlException: 用户'test'登录失败。

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 identifiedusingthe exception stack trace below.

Stack Trace:

[SqlException (0x80131904): 用户'test'登录失败。]

System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)+821651System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)+186System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)+1932System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)+33System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)+172System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)+381System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)+181System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)+173System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)+357System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)+30System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)+424System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)+66System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)+494System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)+82System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)+105System.Data.SqlClient.SqlConnection.Open()+111AuditingDAL.DBHelper.BuildCmd(String sql, SqlParameter[] sqlParms)inD:\doudo_Mamager\Auditing\AuditingDAL\DBHelper.cs:58AuditingDAL.DBHelper.GetDateSet2(String sql, SqlParameter[] values)inD:\doudo_Mamager\Auditing\AuditingDAL\DBHelper.cs:266AuditingDAL.UsersService.GetNowData(String strWhere)inD:\doudo_Mamager\Auditing\AuditingDAL\UsersService.cs:27AuditingBLL.UsersManager.GetNowData(String strWhere)inD:\doudo_Mamager\Auditing\AuditingBLL\UsersManager.cs:18index.btnImg_Click(Object sender, ImageClickEventArgs e)+977System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)+86System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)+115System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)+7System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)+11System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+33System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)+1746

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,需要在项目中安装 `SqlSugar` 包。可以使用 NuGet 包管理器或者命令行安装。 接下来,在 `Startup.cs` 中的 `ConfigureServices` 方法中,添加以下代码: ```csharp services.AddScoped<ISqlSugarClient>((provider) => { var db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = "YourConnectionString", DbType = DbType.MySql, // 指定数据库类型为 MySQL InitKeyType = InitKeyType.Attribute // 指定实体类的主键类型为属性 }); return db; }); ``` 其中,`YourConnectionString` 为你的 MySQL 数据库连接字符串。 然后,在需要使用 `SqlSugar` 的类中,可以通过构造函数注入 `ISqlSugarClient` 对象,例如: ```csharp public class MyService { private readonly ISqlSugarClient _db; public MyService(ISqlSugarClient db) { _db = db; } // ... } ``` 接下来,可以在需要使用定时器的地方,注入 `ISqlSugarClient` 对象,并使用 `SqlSugar` 的查询语句操作数据库。例如: ```csharp public class MyTimerService : IHostedService, IDisposable { private readonly ISqlSugarClient _db; private Timer _timer; public MyTimerService(ISqlSugarClient db) { _db = db; } public Task StartAsync(CancellationToken cancellationToken) { _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); return Task.CompletedTask; } private void DoWork(object state) { var list = _db.Queryable<MyEntity>().ToList(); // 查询 MyEntity 表中的数据 // 处理数据 ... } // ... } ``` 以上代码中,`MyEntity` 可以是实体类,表示数据库中的一张表。可以通过 `SqlSugar` 的 `Queryable` 方法进行查询。同时,`DoWork` 方法会在定时器触发时执行。 这样就完成了在 .NET Core Web Api 中配置 `SqlSugar` 连接 MySQL 数据库并在多个定时器中调用的过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值