我有一个遗留应用程序,我将旧服务器迁移到新服务器上。该应用程序是用VB编写的,我只是将它从一台服务器分叉到另一台服务器。应用程序在其当前位置正常工作,我移动它时所做的唯一更改是更新连接字符串以反映新数据库。出于某种原因,我现在仅在基于堆栈跟踪的OleDB连接字符串上收到以下错误。另一个区别是新服务器上的应用程序使用域帐户来验证数据库而不是SQL帐户。
所以, 1.您可以使用具有OleDB连接的域帐户吗? 2.此错误还有其他原因吗?
提前致谢!
连接字符串:
<add key="ConnectionString" value="SERVER=SQLDEV1\SQLDEV1;DATABASE=Comp_Dev;Integrated Security=SSPI;" />
<add key="SQLConnectionString" value="Provider=SQLOLEDB;Data Source=SQLDEV1\SQLDEV1;Initial Catalog=Comp_Dev;Integrated Security=SSPI;" />
反编译代码:
private void DisplayManagers()
{
this.wkSQL = " SELECT lngManagerID, strName FROM Managers order by strName ";
OleDbConnection oleDbConnection1 = new OleDbConnection(Conversions.ToString(this.Session["database"]));
oleDbConnection1.Open();
OleDbDataReader oleDbDataReader1 = new OleDbCommand()
{
Connection = oleDbConnection1,
CommandText = this.wkSQL,
CommandType = CommandType.Text
}.ExecuteReader(CommandBehavior.CloseConnection);
this.Manager1.DataValueField = "lngManagerID";
this.Manager1.DataTextField = "strName";
this.Manager1.DataSource = (object) oleDbDataReader1;
this.Manager1.DataBind();
this.Manager1.Items.Insert(0, new ListItem());
this.wkSQL = " SELECT lngManagerID, strName FROM Managers order by strName ";
OleDbConnection oleDbConnection2 = new OleDbConnection(Conversions.ToString(this.Session["database"]));
oleDbConnection2.Open();
OleDbDataReader oleDbDataReader2 = new OleDbCommand()
{
Connection = oleDbConnection2,
CommandText = this.wkSQL,
CommandType = CommandType.Text
}.ExecuteReader(CommandBehavior.CloseConnection);
this.Manager2.DataValueField = "lngManagerID";
this.Manager2.DataTextField = "strName";
this.Manager2.DataSource = (object) oleDbDataReader2;
this.Manager2.DataBind();
this.Manager2.Items.Insert(0, new ListItem());
}
错误:
Server Error in '/LicenseCompliance' Application.
--------------------------------------------------------------------------------
The ConnectionString property has not been initialized.
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.InvalidOperationException: The ConnectionString property has not been initialized.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.OleDb.OleDbConnection.PermissionDemand() +1674465
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6600667
System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +27
System.Data.OleDb.OleDbConnection.Open() +47
LicenseCompliance.search.DisplayManagers() in C:\Users\12876\Documents\Visual Studio 2010\Projects\LicenseCompliance\search.aspx.vb:47
LicenseCompliance.search.Page_Load(Object sender, EventArgs e) in C:\Users\12876\Documents\Visual Studio 2010\Projects\LicenseCompliance\search.aspx.vb:34
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
答案 0 :(得分:0)
您需要像这样引用连接字符串:
System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString
答案 1 :(得分:0)
您在配置文件中保存的connectionString不属于OleDB,而是属于SQL Server。 请检查它是否像OLEDB
或者您可以尝试在应用程序中避免使用Oledb并将其传递给SQL 试试这个
imports System.Sql.SqlClient
然后用SQL替换所有OldDb,例如 OleDbCommand 到 SqlComamnd