Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
spawn
Starting Member
1 Post |
Posted - 2008-05-20 : 10:14:28
|
I am trying to populate a SQL 7.0 table from a MVS DB2 table.I'm using an ODBC reader to get the DB2 data and then using SqlBulkCopy to insert the rows into SQL 7.0I keep getting this error - "The given value of type String from the data source cannot be converted to type nvarchar of the specified target column."My Source Table (DB2)- a - integerb - integerc - char(10)d - smallinte - timestampMy Destination Table - a - integerb - integerc - nvarchar(10)d - smallinte - nvarchar(26)And on top of that all columns are nullable.Here is the C# code i'm using - OdbcConnection source = new OdbcConnection(...);SqlConnection dest = new SqlConnection(...);source.Open();dest.Open();OdbcCommand sourceCommand = new OdbcCommand("select * from mytable", source); // using SqlDataReader to copy the rows:using (OdbcDataReader dr = sourceCommand.ExecuteReader()){ using (SqlBulkCopy s = new SqlBulkCopy(dest)) { s.DestinationTableName = "mytable"; s.NotifyAfter = 10000; s.WriteToServer(dr); s.Close(); }}source.Close();dest.Close();If I try to change the nvarchar columns to char then I get this error - "Received invalid column length from bcp client."I've been banging my head with this for quite some time now. Any suggestions?Thanks in advance |
|
DoganFalcon
Starting Member
1 Post |
Posted - 2008-05-21 : 06:12:09
|
I have been searching for similar problem for the last 2 days. I did everything possibly could be done and I found a really simple solution for this. You should take a look at the following link. Length of the column was the key in my case.http://forums.asp.net/p/1228890/2212376.aspxRegards,Murat Yasardogan |
|
|
|
|
|