简体   繁体   English

使用Asp.net MVC连接到SQL Server数据库

[英]Connect to SQL Server database using Asp.net MVC

I'm starting with Asp.net MVC. 我从Asp.net MVC开始。 When connect to SQL Server database then error. 当连接到SQL Server数据库时出错。

This is <connectionStrings> 这是<connectionStrings>

<add name="SGTSVNDBContext" connectionString="Data Source=DESKTOP-ABKAVRM\SQLEXPRESS;Initial Catalog=SGTSVNDBAUTH_CusCloud;Persist Security Info=True;User ID=sa;Password=;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

This is <appSettings> 这是<appSettings>

<add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="DefaultPassword" value="123456" />
    <add key="CustomerKey" value="YN8HgQuslP7kHfMeJk0NyHbu1R2IyHo4neUWmIHlffA=" />
    <add key="GCM-SENDER-ID" value="86033830857" />
    <add key="AUTH-TOKEN" value="AIzaSyB3FLcWcrRlOcu_zyCdl6tMawlvSoX4MeQ" />
    <add key="FCM-SENDER-ID" value="122441061332" />
    <add key="FCM-SERVER-KEY" value="AAAAHIIOU9Q:APA91bGWrJHwfJKiZsRGs8V62_xhuK9x0AWDNewrEnQiPrsrIpZ2YVYKop4Z44LSdNv_iZcSFmHpQ8YxS-WrTniZ5cZMe5T85PKJzv-CTNjTikwc7rqwoIXU--Ssk84IdmBzM8XcYuBb" />
    <!--<add key="BackupPath" value="\\192.168.2.10\SGVN-Server\Scan folder\Phat\" />-->
    <add key="BackupPath" value="D:\Mine\SystemGear\SGVN_SGF #07_2015\Project\Sites\WebAPI\Database_Backup\" />
    <add key="SqlInstanceName" value="SGSOFT09-V2" />
    <add key="BackupDBName" value="SGTSVNDBAUTH_CusCloud" />
    <add key="SqlUserName" value="sa" />
    <add key="SqlPassword" value="" />

When build project then error as the this 当构建项目时错误为

在此处输入图片说明

连接字符串中没有密码,因此无法登录数据库。

If you are sure the SQL Server is in "mixed mode", and that the password is correct for the "sa" account, I can only suggest it to be that the "sa" user doesn't have access to the named database. 如果您确定SQL Server处于“混合模式”,并且密码对于“ sa”帐户是正确的,则只能建议“ sa”用户无权访问命名数据库。

In SQL Management Studio, expand the database branch, then security, then users, and check if the "sa" user appears in the list. 在SQL Management Studio中,依次展开数据库分支,安全性和用户,然后检查“ sa”用户是否出现在列表中。

The best way to diagnose this error is to try and connect to the database server using SQL Management studio, logging in AS the user in the connection string. 诊断此错误的最佳方法是尝试使用SQL Management Studio连接到数据库服务器,并以连接字符串中的AS用户身份登录。 If you can log in, see if you can see your target database in the tree on the left. 如果可以登录,请在左侧的树中查看是否可以看到目标数据库。 Try it with SQL Management Studio from the same machine you're code is running and it should give you more information about what's wrong. 在您正在运行代码的同一台计算机上使用SQL Management Studio尝试一下,它应该为您提供有关出了什么问题的更多信息。

Try changing your connection string to the following: 尝试将连接字符串更改为以下内容:

If the connection string is correct then check for the key value of connection string used in entity framework class. 如果连接字符串正确,则检查实体框架类中使用的连接字符串的键值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM