转到正文

存档

分类: .NET

Error Description:

you may write a stored prcedure which return bigint value, the code can be :

SELECT CAST(SCOPE_IDENTITY() AS BIGINT)

The above statement returns the affected rows of tables and the return value is Big int.  In the .cs file, you may write code to get the return value of this stored procedure:

int id = (int)sqlCommand.ExecuteScalar();

I'm very sorry that the very strange error happen. We'll get the error: System.InvalidCastException: Specified cast is not valid. at....

Solution:

I don't know why this error happen. We can write code as follows to fix the erorr:

int id = (int)(long)sqlCommand.ExecuteScalar();

Why?

the sql command return an object, we firstly cast it into "long" type, and then cast it to "int" type, however, why can we cast it into "int" type directly? I'm so confused, Who can tell me the reasons?

Thank you very much in advanced.

Description:

As we all know, C++(standard) is good at efficiency but is poor at the GUI/CONFIG process. C# is good at GUI/CONFIG but poor at efficiency. The target of this project is to make C++ project as main project, and use C++ to call C# procedure. There are two projects in our project. The first one is C++(Adapter, caller) and the other is C#(Callee). C++ project is a adapter and used to be called by other C++ project. C# is called by adapter and used to do some configuration tasks.

Files List:

  • CsharpComCplusAdapter: 
               1.  CSharpComCPlusplus: a adapter can be called by your C++ project 
               2 . CsharpFront: a C# proejct which do some configuraion tasks 
               3. Lib: the adapter lib, if you want to use this adapter, you must include this lib                                       
               4. ConfigurationCPlusPlusAdapter.h: you must include file in your project. 
               5. CONNECTIONS: you must run rebuild.cmd if you modify the CsharpFront Code. (you must have administrator’s right to run this command)
  • MyApp.exe.config: you must place this file in your solution path. The content of this file can be ignored.
  • MyApp.exe.conifg.config: you must place this file in your solution path. You can config this file to fit your application.

How to use this project:

继续阅读

Suppose you have finished a windows service with a type of "Local Service". The service work well for a long time but break out one day. You can install & unstall the service, however, you can't start the service. You'll get error message: Access is denied.

You can try to modify the type of service to be "Local System".
There's no guarantee it will work. Nevertheless, have a try~ :)
good luck.

I spent one day to solve this problem. Oh, I'm so tired today :(
And I have some gained knowledge about this difficut procedure.

We cannot call C# procedure directly in our C++ program. C# is a .NET language, but C++(not CLI)  has nothing to do with .NET.
You can use C++/CLI to call C# becuase they are both in the same platform.  However, I don't want this result. I want use the standard C++ and we can call C# func directly in our program.

You can visit: http://www.codeproject.com/KB/cs/ManagedCOM.aspx to get important details.

There are some tricks:

  1. the interface in C# program must be public.
  2.  you must have "[assembly: ComVisible(true)]" in your AssemblyInfo.cs files (C# program)
  3. Open your C# project
      - Go to your project's properties (right-click menu)
      - Under the Build tab, make sure the "Register for COM interop" is checked (both for Debugging AND Release
  4. You can use VS GUID generator in Visual studio GUI tools.

继续阅读

Today I created an ASP.Net application that will create excel file.  It works fine when  I am running it on VS studio but fails when i run it on IIS. The error message is

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.

or

Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space

I don't konw why this error will happen. Howerer, I konw the solution given by "amit_de20004" as follows:

Solution:

1. GO to : Control panel -> Administrative tool -> Component Services.
2. Open Component Services .
继续阅读

Today when I want to Install a windows service in a remote computer, I met an error:

An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.

The problem is because that you don't have administrator right.  You must run the install program with Administrator right. It's easy, right click the execuatable program, and "Run as Administrator".

Good Luck!

Reference:

1. Service application installation fail: http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/7cea376a-cab5-497a-927d-0c224e58053b

If you write a windows service, and you choose "Local Service" as account type, and if you want to connect to sql server db, you must use

User ID=*****;Password=***

instead of

integrated security=SSPI

Or you'll get a pemission exception.

Today I want to write a windows serivce application. When I finished the code and I wanted to start the serivce, and I get a error, just like below:

C:\Documents and Settings\Elliot>net start msiserver
The Windows Installer service is starting.
The Windows Installer service could not be started.
 The service did not report an error.
More help is available by typing NET HELPMSG 3534.

C:\Documents and Settings\Elliot>net helpmsg 3534
The service did not report an error.

This error is very strange.  After about 30 minutes, I got the solution as below:

in my case, this was permissions on a log file. If your program code will wrtie some data to a file, and you never change the program execute directory( the service program's default execute directory is C:\windows\system32), and you'll get a error that you have not permission to write to system directory.  However, how to find this error? I looked at the event log which pointed me to this issue. specifically:
1. right click my computer 继续阅读

www.liaoqiqi.com网站PR查询 博客简洁版 博客Google_Site_Map 博客Baidu_Site_Map ?