我需要在 C# 5.0 中的 VisualStudio 2012 中使用 OLEDB 建立 ConnectionString 所以下面是编码:
SQLConn = new SqlConnection("Data Source=STX;Persist Security Info=False;
UserID=JG0149;Password=MYPASS;Initial Catalog=LIBJG");
这些凭证在 STX iSeries 系统上运行良好
有很多使用 VS 2010 和 C# 4.0 的示例,但它不适用于 C# 5.0,类似于 www.connectionstring,com/as-400/中的示例
SQLConn = new SqlConnection("Provider=IBMDA400;Data Source=STX;User Id=JG0149; Password=MYPASS;
Default Collection=LIBJG")
但是VS2012不接受Provider参数并请求其他的
请问有人可以在 VS2012 中使用 ConnectionString 连接到 iSeries 进行共享吗?
最佳答案
SqlConnection专门用于 SQL Server。
使用OleDbConnection以及其他提供商的相关类(class)。
using (var connection = new OleDbConnection(
"Provider=IBMDA400;Data Source=STX;User Id=JG0149; Password=MYPASS;Default Collection=LIBJG"))
{
var command = new OleDbCommand("SELECT NOW() FROM SYSIBM.SYSDUMMY1", connection);
connection.Open();
var reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine(reader.GetString(0));
}
reader.Close();
}
connection.Close();
}
我在 Visual Studio 2012/.NET 4.5 中验证了上述内容。
Microsoft 似乎正在插入回归 ODBC 并逐步淘汰 OLE DB。
SQL Server Blog: Microsoft Aligning with ODBC
The marketplace is moving away from OLE DB and towards ODBC, with an eye towards supporting PHP and multi-platform solutions.
Microsoft SQLNCli team blog: Microsoft is Aligning with ODBC for Native Relational Data Access
We encourage you to adopt ODBC in the development of your new and future versions of your application.
关于.net - C# 5.0 Visual Studio 2012 中 iSeries 的 OLEDB 连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18087252/