[英]Software is not working when MS SQL server version is changed
I'm using SQL Server 2005 database - server in my software (OS-XP). 我在我的软件(OS-XP)中使用SQL Server 2005数据库 - 服务器。 When I changed the server to SQL Server 2008 (OS-windows 7), the software didn't work. 当我将服务器更改为SQL Server 2008(OS-Windows 7)时,该软件无法正常工作。
I debugged the program and found Array index out of bounds exception
in a part of a code, when I changed that code its working fine, can anyone please tell me what is the reason for the problem? 我调试了程序并在代码的一部分中发现了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();
Original code 原始代码
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();
New code 新代码
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();
You need to update your SMO SDK to the SQL 2008 version and remove all of the 2005 references as you are no longer using SQL 2005. 您需要将SMO SDK更新为SQL 2008版本并删除所有2005引用,因为您不再使用SQL 2005。
You can read a bit more on the subject here: 你可以在这里阅读更多关于这个主题:
http://msdn.microsoft.com/en-us/library/ms162129.aspx http://msdn.microsoft.com/en-us/library/ms162129.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.