简体   繁体   English

连接到ASP中的SQL Server数据库

[英]Connection to SQL server database in ASP

I know my question is basic. 我知道我的问题很基本。 But I don't Know how should I configure web.config information! 但是我不知道该如何配置web.config信息!

My SQL server is connected with windows authentication. 我的SQL Server与Windows身份验证连接。 I'm using this config: 我正在使用此配置:

<add key="DBServer" value="mssql" />
<add key="DBSource" value="localhost" />
<add key="DBName" value="TestDB" />
<add key="LoginName" value="KARIM-PC\Karim" />
<add key="LoginPWD" value="" />

but I get this error: 但是我得到这个错误:

{"This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection."} {“此操作需要与'master'数据库的连接。由于原始数据库连接已打开并且凭据已从连接字符串中删除,因此无法创建与'master'数据库的连接。提供未打开的连接。”}

Exception: Thrown: "Login failed for user 'KARIM-PC\\Karim'." 例外:抛出:“用户'KARIM-PC \\ Karim'的登录失败。” (System.Data.SqlClient.SqlException) A System.Data.SqlClient.SqlException was thrown: "Login failed for user 'KARIM-PC\\Karim'." (System.Data.SqlClient.SqlException)引发了System.Data.SqlClient.SqlException:“用户'KARIM-PC \\ Karim'的登录失败。”

Add either <add key="TrustedConnection" value="Yes" /> or <add key="IntegratedSecurity" value="SSPI" /> to force Windows Authentication. 添加<add key="TrustedConnection" value="Yes" /><add key="IntegratedSecurity" value="SSPI" />强制执行Windows身份验证。

You can read more here . 您可以在这里阅读更多内容。

对于窗口身份验证

<add name="MyDbConn"   connectionString="Initial Catalog=MyDataBaseNAme;Data Source=MyServerName;Integrated Security=SSPI;"/>

I recommend you this site: https://www.connectionstrings.com/sql-server/ for getting more information about connection strings. 我建议您访问以下站点: https : //www.connectionstrings.com/sql-server/以获取有关连接字符串的更多信息。 In your case I think it will suits you: 就您而言,我认为它适合您:

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

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

相关问题 SQL Server数据库连接C#ASP.NET - SQL Server Database Connection C# ASP.NET 连接到 SQL Server 数据库 - Connection to SQL Server database 连接到SQL Server数据库文件需要SQL Server 2005 Express或SQL Server 2008 asp net - Connection to SQL Server database files requires SQL Server 2005 Express or SQL Server 2008 asp net 将 SQL 服务器连接转换为 Oracle 数据库连接(ASP.NET Core MVC 和 C#) - Converting SQL Server connection to Oracle database connection (ASP.NET Core MVC & C#) SQL Server数据库连接字符串 - SQL Server Database Connection String 通过ip连接到sql server数据库 - connection to a sql server database by ip 使用SQL 2008的经典ASP中的多数据库连接 - Multiple database connection in classic ASP with SQL 2008 ASP.NET中重用MS Access迁移到SQL Server的数据库连接的最佳做法是什么? - What is the best practice in ASP.NET for re-using a database connection for MS Access migrating to SQL server? 将连接链接到 ASP.NET 中的 SQL 服务器数据库(创建注册页面) - Linking a connection to SQL Server database in ASP.NET (creating signup page) SQL Server数据库连接字符串和ASP.NET Web表单(由Azure托管) - SQL Server Database Connection String & ASP.NET Web Forms (Hosted by Azure)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM