【发布时间】:2017-02-03 13:48:46
【问题描述】:
我有一个控制台应用程序正在连接到 Sql Server 并获取一些值。我在 Select(dbo) 中有架构:
var ds = new DataTable("test");
var connSqlRemoto = new SqlConnection("Server=myserverIP;Database=myDataBase;User Id=user;Password=pass;Integrated Security=False;Connection Timeout=60");
connSqlRemoto.Open();
var nombreBbdd = connSqlRemoto.Database;
var daASqlRemoto = new SqlDataAdapter();
var cmdSqlRemoto = new SqlCommand("SELECT * FROM " + nombreBbdd + ".dbo.myTable;", connSqlRemoto);
cmdSqlRemoto.CommandTimeout = 1200;
cmdSqlRemoto.Parameters.Clear();
daASqlRemoto.SelectCommand = cmdSqlRemoto;
daASqlRemoto.Fill(ds);
我希望架构是动态的。是否可以在连接字符串中传递模式? 像这样的东西不起作用:
Server=myserverIP;Database=myDataBase/dbo;User Id=user;Password=pass;Integrated Security=False;Connection Timeout=60
或
Server=myserverIP;Database=myDataBase.otherSchema;User Id=user;Password=pass;Integrated Security=False;Connection Timeout=60
谢谢。
【问题讨论】:
-
I want teh Schema to be dynamic. So: Is it possible to pass the Schema in the connection string?..当你传入连接字符串时,模式如何是动态的 -
好的,谢谢。 @TheGameiswar 因为它是一个接收不同连接字符串的应用程序。
标签: c# sql-server schema connection-string