[英]Unable to cast object of type 'System.String' to type 'System.Byte[]'. Why?
[英]Migrating working ServiceStack to live causes Unable to cast object of type 'System.Byte' to type 'System.String'
我已經使用基於SQL Server的ORMLite開發了ServiceStack API。 該應用程序可以完美地指向我的本地SQL數據庫和Azure數據庫。 快樂的時光!
現在,我嘗試將這種解決方案移至實時服務器,該服務器具有相同數據庫的本地副本,但結果卻很奇怪。 錯誤是:
Error Code: InvalidCastException
Message: Unable to cast object of type 'System.Byte' to type 'System.String'.
[EMEM: 1/16/2014 11:49:29 AM]: [REQUEST: {Equipment:DP112}]
System.InvalidCastException: Unable to cast object of type 'System.Byte' to type 'System.String'. at lambda_method(Closure , Object , Object ) at
ServiceStack.OrmLite.OrmLiteDialectProviderBase`1.SetDbValue(FieldDefinition fieldDef, IDataReader dataReader, Int32 colIndex, Object instance) at
ServiceStack.OrmLite.ReadExtensions.ExprConvertToList[T](IDataReader dataReader) at ServiceStack.OrmLite.OrmLiteResultsFilterExtensions.ExprConvertToList[T](IDbCommand dbCmd, String sql) at
ServiceStack.OrmLite.ReadConnectionExtensions.Exec[T](IDbConnection dbConn, Func`2 filter) at
ViewPoint.EquipmentService.Get(EMEM request) at
ServiceStack.Host.ServiceRunner`1.Execute(IRequest request, Object instance, TRequest requestDto)
我已經檢查了數據庫架構,它們看起來相同。
這是可以在3個數據庫中的2個上運行的代碼,但不是第3個。
public object Get(EMEM request)
{
var dbFactory = new OrmLiteConnectionFactory(WebConfigurationManager.ConnectionStrings["db"].ToString(), SqlServerDialect.Provider);
using (IDbConnection db = dbFactory.OpenDbConnection())
{
if (request.Equipment == null)
{
List<EMEM> results = db.Select<EMEM>();
return results;
}
else
{
List<EMEM> results = db.Select<EMEM>(p => p.Where(ev => ev.Equipment == request.Equipment));
return results;
}
}
}
我可以通過將連接字符串指向azure數據庫來從字面上解決該問題,這往往表明它與數據庫相關(?)
額外的信息:
誰能建議從哪里開始尋找這個問題?
更新:我現在在本地開發數據庫上創建了一個視圖,因此它現在應該與實時數據庫相同。 我原以為這會破壞本地開發人員站點,但還沒有... :(
答對了! 修復!
它已鏈接到視圖,但這不是視圖的錯。
該視圖正在查看一個表,其中的大多數值具有不同的數據類型。 我要處理的演示表的所有列均設置為String!
因此,當人們為您提供“演示表,具有與實況相同的數據”時,請當心。
它們並不總是相同的!
HTH
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.