GBK –> CP936
GB18030 –> CP54936
Big5 –> CP950
Shift-JIS –> CP932
windows记事本中的编码:
Unicode –> UTF-16LE
Unicode big endian –>UTF-16BE
GBK –> CP936
GB18030 –> CP54936
Big5 –> CP950
Shift-JIS –> CP932
windows记事本中的编码:
Unicode –> UTF-16LE
Unicode big endian –>UTF-16BE
前一段时间看别人的source,发现使用了ThreadLocal,但是当时不知道ThreadLocal是什么,于是在网上查了一下。
下面的链接将的比较详细。我就不转贴了。
参见: http://blog.csdn.net/qjyong/archive/2008/03/08/2158097.aspx
英文状态下:
半角+英文标点:1-=_+qwQW,.
全角+英文标点:1-=_+qwQW,.
中文状态下:
半角+英文标点:1-=_+qwQW,.
全角+英文标点:1-=_+qwQW,.
半角+中文标点:1-=——+qwQW,。
全角+中文标点:1-=——+qwQW,。
从上可知:
英文标点也是区分全角和半角的;
半角字符应该是ascii码,全角字符是中文编码中对应的字符;
只要是全角状态下的都是和一个汉字的宽度一致的,至于它们是几个字节,那和存储的编码格式有关;
1. 变量初始化的的检查:所有变量必须初始化。
2. 逻辑的正确性和完善性:分支(if, switch)处理时的全覆盖,循环的处理等。
3. 异常处理:异常处理的全覆盖,查看是否符合预期的设想。
4. 界限值的测试:对界限值及其附近的值进行测试,看有无异常。
5. 资源释放:内存的释放是否完全,有无重复释放内存等情况。
6. 返回值的检查:返回值是否正确和完全,有无异常返回值等。
7. 错误处理:错误处理是否正确合理,是否完善等。
8. 数组检查:避免数组越界。
9. 函数的使用:对于系统函数或者标准函数的使用是否正确(使用MSCN, man等工具掌握系统函数的使用方法)。
10. 对于Copy, Paste代码的测试:避免产生降级bug。
11. NULL值的检查:使用前要判断是否为NULL,对象释放后要赋为NULL。
12. 文字的处理:半角,全角问题等。
真正的空值 (SQL 中的 NULL)
等同“没有输入的值”,可以出现在大多数类型的字段中(如果没有别的约束条件),SQL server中表示为null,显示为,手工在SQL
server企业管理器中输入的方法是按Ctrl+0。它在.NET中对应System.DBNull.Value。在T-SQL命令中,判断一个值是不
是空值,要用“is null”而不是“=
null”;处理空值有个ISNULL函数,它使用指定的值替换null。用ADO.NET从数据库得到的空值无法自动转化为空字符串或Nothing,
须手动检测:如果得到System.DBNull.Value,则赋给数据对象Nothing或其它自定义的有意义的值。
“”和String.Empty
空字符串(零长度字符串),只出现在字符串类型(如nvarchar)的字段中,SQL server中表示为’’,显示为空白,手工在SQL
server企业管理器中输入时清空一个单元格即可。它在.NET中对应System.String.Empty,也就是我们常用的””。在T-SQL命
令中处理空字符串和处理一般的字符串没什么区别。用ADO.NET从数据库得到的空字符串也和一般的字符串没什么区别。
DBNULL
DBNull在DotNet是单独的一个类型,该类只能存在唯一的实例,DBNULL.Value,DBNull唯一作用是
可以表示数据库中的字符串,数字,或日期,为什么可以表示原因是DotNet储存这些数据的类(DataRow等)都是以 object 的形式来储存数据的。对于
DataRow , 它的 row[column] 返回的值永远不为 null , 要么就是具体的为column 的类型的值 。 要么就是 DBNull 。
所以 row[column].ToString() 这个写法永远不会在ToString那里发生NullReferenceException。DBNull
实现了 IConvertible 。 但是,除了 ToString 是正常的外,其他的ToXXX都会抛出不能转换的错误。
NULL
null 关键字是表示不引用任何对象的空引用的文字值。null 是引用类型变量的默认值。那么也只有引用型的变量可以为NULL,如果 int
i=null,的话,是不可以的,因为Int是值类型的。
If a column in a table is optional, we can insert a new record or update an
existing record without adding a value to this column. This means that the
field will be saved with a NULL value.
NULL values are treated differently from other values.
NULL is used as a placeholder for unknown or inapplicable values.
It is not possible to compare NULL and 0; they are not equivalent.
参见:http://www.w3schools.com/SQL/sql_null_values.asp
http://www.cnblogs.com/liuweitoo/archive/2007/05/05/736625.html
大尾端(Big-Endian):字节的高位在内存中放在存储单元的低端;
小尾端(Little-Endian):字节的高位在内存中放在存储单元的高端;
网络字节序(NBO,Network Byte Order)
使用统一的字节顺序,避免兼容性问题,它一般是Big-Endian;
主机字节序(HBO,Host Byte Order)
不同的机器HBO是不一样的,这与CPU的设计有关,
Motorola 68K系列,HBO与NBO是一致的, (如0xABCD和0xABCD)
Intel X86系列,HBO与NBO不一致。 (如0xCDAB和0xABCD)
参见: http://blog.oracle.com.cn/index.php/306754/viewspace-34235.html
HP-UX
#ps -el
说明:显示的第10个项目是内存使用物理页数(实际使用的物理内存)
getconf PAGE_SIZE 命令可以得到页的大小。
#UNIX95= ps -e -o pid,vsz,args |grep iSMrc_ (单位KB)
说明:这个取得的应该是虚拟内存的大小。
Solaris
#ps –e –o pid,vsz,fname
说明:显示的单位是KB
注意:在Solaris上,得到的内存使用量并不代表准确的malloc量,只能够代表峰值。
malloc后的内存量增加,free后内存量不减少。
Linux
#ps –eo pid,vsz,comm
说明:显示的单位是KB
补充说明:内存的结构分析可以使用pmap工具(Unix)和vadump工具(Win)
在sqlserver surface area configuration中的surface area configuration for services
and connnections, 在remote connections中选择local and remote connections using
tcp/ip only;
在开启防火墙的前期下:将
Microsoft SQL Server/MSSQL.1/MSSQL/Binn/sqlservr.exe 和
Microsoft SQL Server/90/Shared/sqlbrowser.exe添加到防火墙的例外中;
在sql server configuration manager中,将protocols for sqlexpress中的tcp/ip设置成Enable
(可以在它的属性里更改sqlserver的连接端口);
在sql server configuration manager中,将sql server 2005 services中的sql server 和sql
server browser两个服务设置成自动启动,并重启它们;
连接池是可以自动回收无效链接的;
我的机器上的sql server的max_connection 是32767;
所以我写了个测试程序来测试连接池的最大连接数就是max_connection,但是由于连接池自己的回收机制,总是不能如愿,但是发现连接池的Max
Size不管设置多大,不同的机器到最后总是一定的,比方说说是250或336等;每建立一个和连接池的链接,会自动生成一个sqlserver.exe和之对应通信;
只要是连接池的连接字串一样,不管你在哪里链接,都会使用同一个连接池来响应的;
所以说一个连接池的最大连接数目是很小的;sql server的理论最大连接数是32767,但是能不能达到我不知道;
参考:
http://www.sqljunkies.com/WebLog/sqldude/archive/2004/06/14/3146.aspx
http://msdn.microsoft.com/zh-cn/library/8xx3tyca(en-us,vs.71).aspx
http://msdn.microsoft.com/zh-cn/library/ms254503.aspx
源码:
using System; using System.Data.SqlClient; using System.Diagnostics; using
System.Runtime.InteropServices; namespace ConsoleApplication1 { class Program
{ PerformanceCounter[] PerfCounters = new PerformanceCounter[10];
SqlConnection connection = new SqlConnection(); static void Main() { Program
prog = new Program(); // Open a connection and create the performance
counters. prog.connection.ConnectionString =
GetIntegratedSecurityConnectionString(); prog.SetUpPerformanceCounters();
Console.WriteLine(“Available Performance Counters:”); // Create the
connections and display the results. prog.CreateConnections();
Console.WriteLine(“Press Enter to finish.”); Console.ReadLine(); } private
void CreateConnections() { // List the Performance counters.
WritePerformanceCounters(); CreateManyConnetcion(3276800); // Create 4
connections and display counter information. SqlConnection connection1 = new
SqlConnection( GetIntegratedSecurityConnectionString()); connection1.Open();
Console.WriteLine(“Opened the 1st Connection:”); WritePerformanceCounters();
SqlConnection connection2 = new SqlConnection(
GetIntegratedSecurityConnectionString()); connection2.Open();
Console.WriteLine(“Opened the 2nd Connection:”); WritePerformanceCounters();
SqlConnection connection3 = new SqlConnection(
GetIntegratedSecurityConnectionString()); connection3.Open();
Console.WriteLine(“Opened the 3rd Connection:”); WritePerformanceCounters();
SqlConnection connection4 = new SqlConnection(
GetIntegratedSecurityConnectionString()); connection4.Open();
Console.WriteLine(“Opened the 4th Connection:”); WritePerformanceCounters();
SqlConnection connection5 = new SqlConnection(
GetIntegratedSecurityConnectionString()); try { connection5.Open(); } catch
(System.Exception ex) { Console.WriteLine(ex.ToString()); }
Console.WriteLine(“Opened the 5th Connection:”); WritePerformanceCounters();
connection1.Close(); Console.WriteLine(“Closed the 1st Connection:”);
WritePerformanceCounters(); connection2.Close(); Console.WriteLine(“Closed the
2nd Connection:”); WritePerformanceCounters(); connection3.Close();
Console.WriteLine(“Closed the 3rd Connection:”); WritePerformanceCounters();
connection4.Close(); Console.WriteLine(“Closed the 4th Connection:”);
WritePerformanceCounters(); } private void CreateManyConnetcion(int number) {
for (int i = 0; i <= number; i ++) { SqlConnection connection1 = new
SqlConnection( GetIntegratedSecurityConnectionString()); try {
connection1.Open(); } catch (System.Exception ex) {
Console.WriteLine(ex.ToString()); } Console.WriteLine(“Opened the “ + i +”st
Connection:”); WritePerformanceCounters(); if(i > 32765) { Console.Read(); } }
} private enum ADO_Net_Performance_Counters { NumberOfActiveConnectionPools,
NumberOfReclaimedConnections, HardConnectsPerSecond, HardDisconnectsPerSecond,
NumberOfActiveConnectionPoolGroups, NumberOfInactiveConnectionPoolGroups,
NumberOfInactiveConnectionPools, NumberOfNonPooledConnections,
NumberOfPooledConnections, NumberOfStasisConnections // The following
performance counters are more expensive to track. // Enable
ConnectionPoolPerformanceCounterDetail in your config file. //
SoftConnectsPerSecond // SoftDisconnectsPerSecond // NumberOfActiveConnections
// NumberOfFreeConnections } private void SetUpPerformanceCounters() {
connection.Close(); this.PerfCounters = new PerformanceCounter[10]; string
instanceName = GetInstanceName(); Type apc =
typeof(ADO_Net_Performance_Counters); int i = 0; foreach (string s in
Enum.GetNames(apc)) { this.PerfCounters[i] = new PerformanceCounter();
this.PerfCounters[i].CategoryName = “.NET Data Provider for SqlServer”;
this.PerfCounters[i].CounterName = s; this.PerfCounters[i].InstanceName =
instanceName; i++; } } [DllImport(“kernel32.dll”, SetLastError = true)] static
extern int GetCurrentProcessId(); private string GetInstanceName() { //This
works for Winforms apps. string instanceName =
System.Reflection.Assembly.GetEntryAssembly().GetName().Name; // Must replace
special characters like (, ), #, /, // string instanceName2 =
AppDomain.CurrentDomain.FriendlyName.ToString().Replace(‘(‘, ‘[‘)
.Replace(‘)’, ‘]’).Replace(‘#’, ‘‘).Replace(‘/‘, ‘‘).Replace(‘//‘, ‘‘); //
For ASP.NET applications your instanceName will be your CurrentDomain’s //
FriendlyName. Replace the line above that sets the instanceName with this: //
instanceName =
AppDomain.CurrentDomain.FriendlyName.ToString().Replace(‘(‘,’[‘) //
.Replace(‘)’,’]’).Replace(‘#’,’‘).Replace(‘/‘,’‘).Replace(‘//‘,’‘); string
pid = GetCurrentProcessId().ToString(); instanceName = instanceName + “[“ +
pid + “]”; Console.WriteLine(“Instance Name: {0}”, instanceName);
Console.WriteLine(“—————————“); return instanceName; }
private void WritePerformanceCounters() {
Console.WriteLine(“—————————“); foreach (PerformanceCounter
p in this.PerfCounters) { Console.WriteLine(“{0} = {1}”, p.CounterName,
p.NextValue()); } Console.WriteLine(“—————————“); } private
static string GetIntegratedSecurityConnectionString() { // To avoid storing
the connection string in your code, // you can retrive it from a configuration
file. return @”Data Source=192.168.10.3/SQLEXPRESS;Connection Lifetime
=1;Initial Catalog=test;User ID=sa;Password=1;Max Pool Size=32769;Min Pool
Size=0;”; } private static string GetSqlConnectionString() { // To avoid
storing the connection string in your code, // you can retrive it from a
configuration file. return @”Data Source=192.168.10.2/SQLEXPRESS;Initial
Catalog=test;User ID=sa;Password=1;”; // “Initial Catalog=AdventureWorks”; }
private static string GetSqlConnectionStringDifferent() { // To avoid storing
the connection string in your code, // you can retrive it from a configuration
file. return @”Data Source=192.168.10.1/SQLEXPRESS;Initial Catalog=test;User
ID=sa;Password=1;Max Pool Size=100;Min Pool Size=0;”; } } }
To view the current server activity
USE master
EXEC sp_who
To view the data space information for a database
USE examsysdb
EXEC sp_spaceused ‘TB_PagePersistenceInfo’
To view the log space information for a database
use master
select * from sysperfinfo
To view general statistics about SQL Server activity and usage
USE master
EXEC sp_monitor
For each column, the statistic is printed in the form number(number)-number%
or number(number). The first number refers to the number of seconds (for
cpu_busy, io_busy, and idle) or the total number (for the other variables)
since SQL Server was restarted. The number in parentheses refers to the number
of seconds or total number since the last time sp_monitor was run. The
percentage is the percentage of time since sp_monitor was last run. For
example, if the report shows cpu_busy as 4250(215)-68%, the CPU has been busy
4250 seconds since SQL Server was last started up, 215 seconds since
sp_monitor was last run, and 68 percent of the total time since sp_monitor was
last run.
Reports the account, the type of account, the privilege level of the
account, the mapped login name of the account, and the permission path by
which an account has access to Microsoft® SQL Server™.
USE master
exec xp_logininfo