连接到 SQL 服务器时连接字符串抛出错误

Connection Strings Throw an Error when Connecting to SQL Server

我正在尝试将旧的 Web 应用程序从独立 Windows 2008 服务器移动到 2012 R2 服务器,该服务器处于生产环境中,用于其他一些 Web 应用程序。

我将 SQL Server 数据库移动到专用的 SQL Server 2012,并设置域用户来连接和管理应用程序。我一直收到以下错误,但我不确定为什么用户无法连接。

这些是敏感信息已更改的连接字符串:

<add name="CslaExConnection" 
     connectionString="Database=Databasev3;Server=Server\Instance,50000;User=Domain\User;Password=P@ZZWORD;Enlist=false;" 
     providerName="System.Data.SqlClient" />
<add name="ConnectionString" 
     connectionString="Data Source=Server\Instance,50000;Initial Catalog=Databasev3;Persist Security Info=True;User ID=Domain\User;Password=P@ZZWORD" 
     providerName="System.Data.SqlClient" />
<add name="ConnectionString1" 
     connectionString="Data Source=Server\Instance,50000;Initial Catalog=Databasev3;Persist Security Info=True;User ID=Domain\User;Password=P@ZZWORD" 
     providerName="System.Data.SqlClient" />
<add name="Tools" 
     connectionString="Data Source=Server\Instance,50000;Initial Catalog=Databasev3;Persist Security Info=True;User ID=Domain\User;Password=P@ZZWORD" 
     providerName="System.Data.SqlClient"/>
<add name="MySQLConnection" 
     connectionString="Server=127.0.0.1;Database=MySQLDB;Uid=root;Pwd=P@ZZWORD;Port=3306;Allow Zero Datetime=True;" 
     providerName="MySql.Data.MySqlClient"/>
<add name="CslaExConnectionSynergyContact" 
     connectionString="Database=goldmine;Server=Server\Instance,50000;User=Domain\User;Password=P@ZZWORD;Enlist=false;" 
     providerName="System.Data.SqlClient" />
<add name="ConnectionString2" 
     connectionString="Data Source=Server\Instance,50000;Initial Catalog=Databasev3;Persist Security Info=True;User ID=Domain\User;Password=P@ZZWORD" 
     providerName="System.Data.SqlClient"/>

这是我登录应用程序时收到的错误:

Server Error in '/md3' Application.

Login failed for user 'domain\user'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'domain\user'.

Source Error:

Line 45: PagingListFilter filter = new PagingListFilter(info);
Line 46: filter.PageSize = 0;
Line 47: GenericPagedList list = appUser.GetList(filter);
Line 48: DataTable dt = list.Results;
Line 49: if (dt.Rows.Count > 0)

Source File: d:\HTTP\wwwroot\synergytools\md3\loginold.aspx.cs Line: 47

Stack Trace:

[SqlException (0x80131904): Login failed for user 'domain\user'.] System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +428 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117 System.Data.SqlClient.SqlConnection.Open() +122 DFramework.Database.Query.ExecutePagedCommand() in D:\DCPL\Framework\DFramework\Database\Query.cs:508

[QueryException: SELECT COUNT(*) FROM (SELECT * FROM vwAppUserList

 WHERE OldUserId = @OldUserId
) count__Query
@OldUserId = 111
]
   DFramework.Database.Query.ExecutePagedCommand() in D:\DCPL\Framework\DFramework\Database\Query.cs:560
   DFramework.Business.BusinessBase.ListData(Query query) in D:\DCPL\Framework\DFramework\Business\BusinessBase.cs:495
   DFramework.Business.BusinessBase.List(Query query) in D:\DCPL\Framework\DFramework\Business\BusinessBase.cs:187
   DFramework.UI.BusinessBase`1.GetList(PagingListFilter filter) in D:\DCPL\Framework\DFramework.UI\BusinessBase.cs:73
   loginold.GetAppUserId(Int32 oldUserId) in d:\HTTP\wwwroot\synergytools\md3\loginold.aspx.cs:47
   loginold.Page_Load(Object sender, EventArgs e) in d:\HTTP\wwwroot\synergytools\md3\loginold.aspx.cs:22
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Version Information: Microsoft .NET Framework Version:2.0.50727.8009; ASP.NET Version:2.0.50727.8015

您可以检查服务器连接,您可以在桌面上创建一个空文件并将其保存为 .udl 扩展名。现在打开它,您可以创建连接并进行测试。

完成后,如果用记事本打开.udl 文件,您可以看到字符串连接。如果您使用的是域帐户,请记住使用 "integrated security = SSPI"。

这里有一个使用 .udl 文件创建和测试连接的教程:link .udl

希望对您有所帮助!

凯扎克,

您不能在连接字符串中指定域用户帐户和密码,因为它会将其视为 SQL 服务器身份验证登录。因此,如果您使用域用户帐户 运行 应用程序,您的连接字符串将采用以下格式:

Data Source=myServerAddress;Initial Catalog=DataBase;Integrated Security=SSPI;