为什么会出现字符串的连接问题?
程序:碰到郁闷的问题,见程序红色部分using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///使用 WebConfigurationManager需要引用的空间
using System.Web.Configuration;
///使用 SqlConnection需要引用的空间
using System.Data.SqlClient;
/// <summary>
///StudentDB 的摘要说明
/// </summary>
public class StudentDB
{
String connectionString;
public StudentDB()
{
connectionString = WebConfigurationManager.ConnectionStrings["Student"].ConnectionString;
}
public StudentDB(string connectionString)
{
this.connectionString = connectionString;
}
public string TestConnection() //测试数据库是否链接成功
{
String databaseInfo;
SqlConnection con = new SqlConnection(connectionString);
try
{
con.Open();
databaseInfo = "<b>Server Version:</b>" + con.ServerVersion;
databaseInfo += "<br/><b>Connection Is:</b>" + con.State.ToString();
}
catch (Exception ex)
{
databaseInfo = "ERROR Reading the database." + ex.Message;
}
finally
{
con.Close();
databaseInfo+= "<br/><b>Now Connection is :</b>" +
con.State.ToString();
这里出错了,提示说是“使用了未赋值的局部变量“databaseInfo”可前面我不是已经赋了值吗”
}
return databaseInfo;
}
}