无法打开数据库。在安装 .NET 应用程序时创建 SQL 服务器数据库时因用户错误登录失败

Cannot open database. Login failed for user error when creating SQL Server database while installing a .NET app

我使用 VS 2010 和 SQL Server 2008 数据库创建了一个 .net 应用程序。我按照 link 中的说明部署了该应用程序: http://techbrij.com/install-sql-server-database-with-visual-studio-setup

但是每次安装应用程序时,我都会遇到异常:

Cannot open database "PharmacyDb" requested by the login.the login failed. Login failed for user 'Bahaa-PC\Bahaa".

我尝试 运行 以管理员身份安装并允许 SQL 服务器通过 Windows 防火墙,但我仍然遇到此异常。

注意:我有 3 个 SQL 脚本文件来创建我的数据库,当我在 VS 或 SQL Server Management Studio 中执行它们时,它们完美地创建了数据库。

我错过了什么?

注2:这是install.cs中的连接字符串 class:

 string connStr = "Data Source=" + serverName + ";Initial Catalog=" + dbName + ";Integrated Security=True";

更新: 日志文件:

2017-05-13 13:13:17.60 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-13 13:13:17.60 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2017-05-13 13:23:10.03 spid52      Attempting to load library 'xpstar.dll' into memory. This is an informational message only. No user action is required.
2017-05-13 13:23:10.10 spid52      Using 'xpstar.dll' version '2009.100.1600' to execute extended stored procedure 'xp_instance_regread'. This is an informational message only; no user action is required.
2017-05-13 13:24:34.49 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-13 13:24:34.49 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2017-05-13 13:35:12.71 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-13 13:35:12.71 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2017-05-13 13:36:55.95 spid53      Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2017-05-13 13:36:55.99 spid53      Using 'xplog70.dll' version '2009.100.1600' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.
2017-05-13 14:03:27.26 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-13 14:03:27.26 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2017-05-13 14:07:27.27 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-13 14:07:27.27 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2017-05-13 14:07:56.66 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-13 14:07:56.66 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2017-05-13 14:11:45.57 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-13 14:11:45.57 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]
2017-05-14 00:37:36.40 Server      Server resumed execution after being idle 35916 seconds: user activity awakened the server. This is an informational message only. No user action is required.
2017-05-14 00:37:41.48 Logon       Error: 18456, Severity: 14, State: 38.
2017-05-14 00:37:41.48 Logon       Login failed for user 'Bahaa-PC\Bahaa'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]

经过多次尝试,我发现问题是我在安装程序 class 中使用了一个需要连接到数据库的对象,所以我删除了它。