dotNET Trouble Shooting

1. 由于启动用户实例的进程时出错,导致无法生成 SQL Server 的用户实例。该连接将关闭。(Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.)

这个问题是在尝试从VS2008的解决方案试图里直接打开mdf文件时见到的。

据称是微软的bug,删除一个目录就行,试了一下,删除下面这个文件夹:C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS

确实解决了问题,不过我发现实际上在打开了数据库文件之后,这里会重新被创建一个SQLEXPRESS文件夹。


Ref: http://www.cnblogs.com/GDLMO/archive/2009/12/14/1623760.html


2. Suppose we have a web,config which contains something like:

<configuration>
	...
	<appSettings>
		...
		<add key="UPLOADMEDIA_SAVEFOLDER" value="C:\UploadMedia" />
		...
	</appSettings>


	...


If the path contains space, like: 'my path', then ASP,NET throws an exception during execution. So far there is no solution to the issue.


So, think of it in another way, to create a new folder on C drive, but still got AccessException:



Ref:

http://stackoverflow.com/questions/18058244/asp-net-application-cannot-write-to-folder


3. Assemble 'XXX' uses 'XXX', which has a higher version than referenced assembly 'XXX'


I got an compilation error as:

"Assembly 'Microsoft.Practices.Unity.Configuration, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
uses 'Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
which has a higher version than
referenced assembly 'Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
C:\ClubS\souce\MySamSung.Basic\bin\Debug\Microsoft.Practices.Unity.Configuration.dll"


Double click the reference of the assembly 'Microsoft.Practices.Unity' in solution explorer, and locate its path property in property explorer, I found it was something like: C:\Windows\assembly\GAC_MSIL\Microsoft.Practices.Unity\1.2.0.0_xxxxxxxxx\Microsoft.Practices.Unity.dll, of which the version was 1.2.0.0.


Go to the path C:\Windows\assembly\, I found there is a 1.2 version Microsoft.Practices.Unity.dll:



And on the other hand, I have another environment looks like:


which works fine. Since it was referencing to the assembly inside the solution instead of the version coming with Windows 7.


Here is the solution:

Hover the mouse over the problematic reference and right click, and select 'Remove' in the brought up menu, and then hover the cursor over the 'References' and then right click, select 'Add Reference...', then select 'Browse', locate the .dll file.






Ref:

http://stackoverflow.com/questions/9219832/error-cs1705-which-has-a-higher-version-than-referenced-assembly


4. The cast to value type 'XXX' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.


In my case, the 'XXX' is actually DateTime type. The problem started from adding a Datetime field(null allowed) to a table in a project which I took over from othes in middle of its development. So, the following is what I have done:

  • a). Added one DateTime type field named 'record_datetime';
  • b). Update the model from database in Entity Framework;
  • c). There is a custom model class for the table in question:
    public class clsTableReturn
    {
    	public string img_1
    	{
    		get
    		{
    			clsFileMgr objFile = new clsFileMgr();
    			return objFile.getFilePath(this.redeemitem_img_1);
    		}
    	}
    
    	// Table record
    	public int id { set; get; }
    	public int quantity { set; get; }
    	public Int16 status { set; get; }
    	public string remark { set; get; }
    	public int lastModifiedBy { set; get; }
    	public DateTime lastModifiedTime { set; get; }
    	
    	...
    }
    
    Added one line to the class definition body:
    public DateTime record_datetime { set; get; }
  • d). Made use of the custom class 'clsTableReturn' in controller:
    var records = new List<clsTableReturn>();
    records = objEntity.ExecuteStoreQuery<clsTableReturn>(strSQL).ToList();
    objEntity is the data context object in EF.


And then I got the exception, InvalidOperationException: The cast to value type 'DateTime' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.


The solution is to put a question mark after 'DateTime', making it nullable:

public DateTime? record_datetime { set; get; }



Ref: Entity Framework InvalidOperationException





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值