我在我的软件 (OS-XP) 中使用 SQL Server 2005 数据库 - 服务器。当我将服务器更改为 SQL Server 2008 (OS-windows 7) 时,该软件无法运行。
我调试了程序并Array index out of bounds exception
在代码的一部分中发现,当我更改该代码时它工作正常,谁能告诉我问题的原因是什么?
String cnnStr = String.Format("Data Source = {0}; Initial Catalog = {1}; Integrated Security = SSPI; persist security info=False; Trusted_Connection=Yes",ServerName, Databasae);
sqlConnection = new SqlConnection(cnnStr);
sqlConnection.Open();
原始代码
Server server = new Server(new ServerConnection(sqlConnection));
Database db = server.Databases[Databasae];
Table Table = new Table(db, TableName);
Column TimeColumn = new Column(Table, "DateTime");
TimeColumn.DataType = DataType.DateTime;
TimeColumn.Nullable = false;
Column ValueColumn = new Column(Table, "Value");
ValueColumn.DataType = DataType.Float;
ValueColumn.Nullable = false;
Table.Columns.Add(TimeColumn);
Table.Columns.Add(ValueColumn);
Table.Create();
新代码
StringBuilder query = new StringBuilder();
query.Append("CREATE TABLE ");
query.Append(TableName);
query.Append(" ( [DateTime] DateTime , Value float(10) )");
SqlCommand sqlQuery = new SqlCommand(query.ToString(), sqlConnection);
SqlDataReader reader = sqlQuery.ExecuteReader();
reader.Close();