Sunday, June 22, 2008

Set proxy for WebRequest in web.config

Put this in web.config, you can set usesystemdefault but for me that dont work.


<system.net>
<defaultproxy>
<proxy
usesystemdefault="false"
proxyaddress="http://192.168.1.1:3128"
bypassonlocal="true"
</proxy>
</defaultproxy>
</system.net>

Keys: asp.net, webrequest, proxy.

RESTORE cannot process database because it is in use by this session

"System.Data.SqlClient.SqlError: RESTORE cannot process database because it is
in use by this session. It is recommended that the master database be used
when performing this operation."

If you are using Microsoft.SqlServer.SMO set SqlServer.ConnectionContext.DatabaseName to "master".
If you are using TSQL, select master database (USE master).

Keys: error, smo, tsql, c#.

Friday, April 11, 2008

C# DataGridView and Multithreading Problem

I had some problems updating datagridview from another thread. Problem is in painting scrollbars (vertical one). One thing that is interesting is that everything is working fine if you start your program from VisualStudio debugger.

My first solution to this problem was: I've disabled scrollbars and application works fine.

After some time of research I've found solution to my problem!!!

to simplify there is two posibilities:

1. you have datagridview without binded datasource
Solution: use delegate to add rows, or update existing.

2. you have datagridview with binded datasource (for example datatable)
Solution: use delegate to update datatable/datasource,

if you dont now how, you can start from this article.


keys: c# datagridview multithread freeze, scrollbar problem, c# application freeze, program hangup, multithread gui update, datagridview update from another thread, threading, csharp.

Tuesday, March 18, 2008

How to convert string to byte[]

Here is a litle function to convert string to byte array.


public static byte[] StringToByteArray(string inputString)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(inputString);
}

Sunday, March 16, 2008

Deserialization failed: The type initializer for "Microsoft.ReportDesigner.Drawing.Language" threw an exception.

I had this error because I registered custom CultureInfo with same name that already exists in collection.

Above is peace of code that you can use to check if you have the same problem. If this code don't throw an exception, than you have some other problem.



private void test()
{
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
Hashtable hashtable = new Hashtable();
ArrayList m_languages = new ArrayList();
hashtable.Add("", "Default");
m_languages.Add("");
for (int i = 0; i < cultures.Length; i++)
{
CultureInfo info = cultures[i];
if (info.Name != "")
{
hashtable.Add(info.Name, info.DisplayName);
}
}
}

Friday, February 8, 2008

Welcome to the C# Programming Reference

I've created this blog as reference to C# programming tools, articles, and free/open source code.