日期:2014-05-18  浏览次数:20876 次

用QueryTables.add方法时,server与data source是否有区别?
我是小菜鸟,想请教各路大侠一个问题:
server 与 data source是否有区别?
database 与 Initial Catalog是否有区别?

我原认为是一样的,但是,今天悲剧了,请看下面两个程序
用连接字串1,运行正常
用连接字串2,报错
-_-||| 某菜鸟百思不得其解,MS网上很多人说是一样的

我的程序是:
using MsExcel=Microsoft.Office.Interop.Excel;

OPrange=自己设置了一个区域(已经验证,没有错的)
sqlstr=SQL语句(也没有错)

MsExcel.QueryTable xldt=null;
MsExcel.QueryTables xldts=sheet.QueryTables;

// 连接字串1
sqlconn1="OLEDB;Provider=SQLOLEDB.1;Data Source=CodeGirl;Uid=sa;Password=123;Initial Catalog=try;Persist Security Info=False;";
xldt=(MsExcel.QueryTable)xldts.add(sqlconn1,OPrange,sqlstr)
xldt.RefreshStyle=MsExcel.XlCellInsertionMode.xlInsertEntireRows;
xldt.Refresh(False);

//连接字串2
sqlconn2="OLEDB;Provider=SQLOLEDB.1;Server=199.34.51.51;Database=try;Uid=sa;Password=123;Persist Security Info=False;";
xldt=(MsExcel.QueryTable)xldts.add(sqlconn2,OPrange,sqlstr)
xldt.RefreshStyle=MsExcel.XlCellInsertionMode.xlInsertEntireRows;
xldt.Refresh(False);



------解决方案--------------------
http://topic.csdn.net/u/20100416/18/f5eb54c3-58c4-4890-af43-a015e30735cc.html
关于这个的讨论太多···
有不少人推荐使用这个:Data Source。说这个是标准写法···