I’m using SQL Server 2005 database – server in my software (OS-XP). When I changed the server to SQL Server 2008 (OS-windows 7), the software didn’t work.
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?
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.
You can read a bit more on the subject here:
http://msdn.microsoft.com/en-us/library/ms162129.aspx