加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – 使用connectionStringName进行数据库日志记录

发布时间:2020-12-16 00:12:51 所属栏目:asp.Net 来源:网络整理
导读:这是我的nlog.config文件.我已经打开了throwsException. nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" targets target type="Database" name="databaseLog" d
这是我的nlog.config文件.我已经打开了throwsException.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  throwExceptions="true">
      <targets>   
        <target type="Database" name="databaseLog"
        dbProvider="sqlserver"   connectionstring="server=.SQLExpress;database=Movie;integrated security=true">
            <commandText>
                INSERT INTO [Log] ([Description],[Level] ) VALUES (@Description,@Level )
            </commandText>
            <parameter name="@Description" layout="${message}"/> 
            <parameter name="@Level" layout="${level}"/>
        </target>

      </targets>

      <rules>
         <logger name="*" minLevel="Trace"  appendTo="databaseLog"/> 
      </rules>
</nlog>

这将工作并将记录插入数据库.但是我想使用connectionstringName而不是重新键入connectionstring.
当我将connectionstring更改为connectionstringname时,这样….

connectionstring="server=.SQLExpress;database=Movie;integrated security=true"

connectionStringName="ApplicationConnectionString"

我收到一个错误
期望’providerInvariantName’参数的非空字符串

解决方法

将System.Data.SqlClient添加到web.config / app.config中连接字符串中的ProviderName属性:
<add name="ApplicationConnectionString" 
providerName="System.Data.SqlClient"
connectionString="server=.SQLExpress;database=Movie;integrated security=true;"/>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读