当我尝试在 C# 中编写与我的应用程序到我的数据库的连接时,我在 Visual Studio 2005 中成功构建了应用程序,但是当我在调试器中运行该站点时出现错误:
Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 118.
这是给出错误的连接代码:
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Server"].ConnectionString);
我在我的 web.config 文件中正确写入了连接字符串,所以我对这远程意味着什么一无所知。我不确定我是否遗漏了什么。任何帮助表示赞赏。这是我可能有帮助的部分的完整代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Data.SqlClient;
public partial class RateAnalyzerPage: System.Web.UI.Page
{
protected void Search_Click(object sender, EventArgs e)
{
string IDnumber = mechantNumber.Text;
string selectSQL = "SELECT FROM Authors Where MID='"+ IDnumber +"'";
// SqlConnection con = new SqlConnection(@"Server=");
//SqlConnection con = new SqlConnection();
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Server"].ConnectionString);
SqlDataReader reader;
try
{
con.Open();
SqlCommand cmd = new SqlCommand(selectSQL, con);
reader = cmd.ExecuteReader();
while (reader.Read())
{
QualVol.Text = reader["TotalVolume"].ToString();
}
reader.Close();
}
catch (Exception err)
{
}
finally
{
con.Close();
}
}
}
如果我错过了一些有用的数据,请告诉我。
这是连接字符串: