[问题] 连SQL SERVER没问题,但无法切换数据库?

楼主: Competitive (...)   2014-05-27 08:51:32
各位好
目前在看一支程式(程式码在最后)
目前使用正常,但问题在于SqlConnection
("server=(local)\\SQLEXPRESS;database=abc;uid=sa;password=abc"
在SQL SERVER中还有另一个数据库为abc2
但我的SQLEXPRESS中的database如果改为abc2,仍会连abc
请问在C#中切换数据库还要作什么处理吗?
还是函式中CALL的DATABASECONNECT()其实是另一只程式的
问题很菜很浅,但仍请指教
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.Data.SqlClient;
namespace AAA
{
public partial class AddEmp : System.Web.UI.Page
{
protected DataSet myDataSet;
SqlConnection conn;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["EmpID"] == null)
{
Response.Write("<script>window.parent.location.href='Logon.aspx';</script>");
}
else
{
if (!IsPostBack)
{
Button1.Attributes["onclick"] = "javascript:return
confirm('确定加入?');";
InitDropItems();
bind();
}
}
}
private void DatabaseConnect()
{
conn = new
SqlConnection("server=(local)\\SQLEXPRESS;database=abc;uid=sa;password=abc");
conn.Open();
}
protected void InitDropItems()
{
try
{
DatabaseConnect();
//煦?蹈桶
SqlCommand tmpcmd = new SqlCommand("Select * from DropItems
where ItemName='煦?' and Visible=1", conn);
tmpcmd.CommandType = CommandType.Text;
SqlDataAdapter tmpadp = new SqlDataAdapter();
tmpadp.SelectCommand = tmpcmd;
DataSet tmpds = new DataSet("ddlTeam");
tmpadp.Fill(tmpds);
楼主: Competitive (...)   2014-05-27 08:55:00
是否像JSP一样其实要先编译成CLASS才能运作?
作者: johnpage (johnpage)   2014-05-27 13:03:00
连线字串怪怪的
作者: netnk (不平凡的常人...)   2014-05-28 22:48:00
conn.close()

Links booklink

Contact Us: admin [ a t ] ucptt.com