[置顶] 中华人民共和国劳动合同法

[置顶] 学习资源收藏[2007-04-18更新]

[置顶] 常用CHM帮助文档集锦下载[2008-08-24更新]

安装 SQL Server 2008 时可能需要 Visual Studio 2008 SP1

Visual Studio 2008 不支持将不带 Service Pack 的 Visual Studio 2008 与 Visual Studio 2008 SP1 安装在同一台计算机上。由于 SQL Server 2008 的某些功能将安装的组件同时也是 Visual Studio 2008 SP1 发行版本的一部分,因此 SQL Server 2008 需要 Visual Studio 2008 SP1。如果改为安装了不带 Service Pack 的 Visual Studio 2008,那么在安装 SQL Server 2008 后,它将无法正常运行。

标签:

SQLite Manager

管理你电脑上的任何 SQLite数据库。一个直观的目录树状来展示数据库的对象。通过提示对话来管理表、索引、视图和触发器。你能浏览和搜索这些表,还能增加、修改或删除记录。快捷地执行任何sql查询。一个下拉菜单sql语法帮助,让编写sql变得轻松。通过菜单、工具条、按钮、和关联菜单来简易地进行相同的操作。

标签:

SQLite数据库

SQLite是一个老牌的轻量级别的文件数据库,完全免费,使用方便,不需要安装,无须任何配置,也不需要管理员。它是开源的嵌入式数据库产品,是同类产品中的后起之秀,2005年获得了开源大奖,而且最新的PHP5也内嵌了SQLite。相比另一款著名的嵌入式数据库——Berkely DB。SQLite是关系型数据库,支持大部分SQL语句,这是它比BDB优秀的地方。作为一款嵌入式数据库,SQLite与Berkely DB一样,以库的形式提供,通过C函数直接操作数据库文件。(也支持其他的访问方式,比如Tcl)。下载包中有SQLite3.dll和 SQlite3.def,def可以用VC的lib工具生成链接库,当然也可以直接链接dll文件。SQLite不是Server,所以和SQLServer等不同,它和程序运行在同一进程。中间没有进程间通信,速度很快,而且体积小巧,易于分发。适合运行在单机环境和嵌入式环境。(随便说一下,腾讯的QQ中可能就用到了SQLite数据库来保存信息)

标签:

SQL Injection Attack (防止SQL注入)

(Special thanks to Neil Carpenter for helping out on this blog post)

Recent Trends

Beginning late last year, a number of websites were defaced to include malicious HTML <script> tags in text that was stored in a SQL database and used to generate dynamic web pages. These attacks began to accelerate in the first quarter of 2008 and are continuing to affect vulnerable web applications.

The web applications compromised share several commonalities:

  • Application uses classic ASP code
  • Application uses a SQL Server database
  • Application code generates dynamic SQL queries based on URI query strings (http://consoto.com/widgets.asp?widget=sprocket)

This represents a new approach to SQL injection (http://msdn.microsoft.com/en-us/library/ms161953.aspx). In the past, SQL injection attacks were targeted to specific web applications where the vulnerabilities and the structure of the underlying database were either known or discovered by the attacker. This attack differs because it has been abstracted such that it is possible to attack virtually any vulnerability that is present in an ASP page creating dynamic SQL queries from URI query strings. Additional technical details and a walkthrough of the specifics are available at http://blogs.technet.com/neilcar/archive/2008/03/15/anatomy-of-a-sql-injection-incident-part-2-meat.aspx.

This attack does not exploit vulnerabilities in Windows, IIS, SQL Server, or other infrastructure code; rather, it exploits vulnerabilities in custom web applications running on this infrastructure. Microsoft has investigated these attacks thoroughly and determined that they are not related to any patched or 0-day vulnerabilities in Microsoft products. More information can be found at http://blogs.technet.com/msrc/archive/2008/04/25/questions-about-web-server-attacks.aspx.

As indicated above, these attacks have been accelerating through the year. This would appear to be related to at least two factors. First, there is a malicious tool that is in the wild that automates this. SANS discusses that tool here -- http://isc.sans.org/diary.html?storyid=4294. The tool uses search engines to find vulnerable sites to SQL injection.

The second factor is that one or more malicious bots are now launching SQL injection attacks as a way of spreading the bot further. SecureWorks discusses an example at http://www.secureworks.com/research/threats/danmecasprox/.

Once a server has been defaced using this attack, it will begin including a malicious <script> tag pointing to a .js file. While the contents of these files differ, they all attempt to exploit various vulnerabilities including already-patched Microsoft vulnerabilities and vulnerable third-party ActiveX controls. Since these scripts are hosted independently, it is possible that the scripts can be changed rapidly to exploit new client vulnerabilities and can be easily tailored to target on a “per browser” basis.

IT/database administrators Recommendations

There are a number of things that IT administrators and database administrators should do to limit risk and respond to possible incidents on the code and infrastructure they manage:

  • Review IIS logs and database tables for signs of previous exploits

Since this exploit takes place via the URI query string, administrators can review IIS logs to find anomalous queries that may be attempts to exploit this. Information on how to do this manually is available at http://blogs.technet.com/neilcar/archive/2008/03/15/anatomy-of-a-sql-injection-incident-part-2-meat.aspx. A sample of an automated tool is available at http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=WSUS&ReleaseId=13436.

If IIS logs show that the server has possibly been exploited, the next step would be to inspect tables in databases that are used by the associated web applications, looking for <script> tags appended to cells in text columns.

NOTE: IIS servers should never run in production with logging disabled. While the storage and administration requirements of IIS logging can be significant, the lack of IIS logs makes it very difficult to respond to security incidents.

  • If running 3rd party code that uses a database back-end, consult ISV about susceptibility to SQL injection

In cases where 3rd party ASP web applications are being used, administrators should contact the application vendors to ensure that they are not susceptible to SQL injection attacks.

  • Validate that the account(s) that are used from the web application have least possible privilege in the database

Administrators should make sure that the SQL users that the web application uses have the least privilege necessary. Web applications should never connect as users with administrative privilege such as “sysadmin” at the server level or “db_owner” at the database level. The white paper “best practices for setting up and maintaining security in SQL Server 2005” http://download.microsoft.com/download/8/5/e/85eea4fa-b3bb-4426-97d0-7f7151b2011c/SQL2005SecBestPract.doc provides recommendations for various aspects of SQL server security.

Web developers Recommendations

There are several good documents on how Web developers can prevent SQL injection attacks when writing code. Since these attacks leverage vulnerable web application code, the only way to completely prevent them is to resolve vulnerabilities in the code. Any place that the code dynamically generates a SQL query using data from an external source (and, particularly, from a URI query string) should be considered suspect. Once code vulnerabilities are identified, they need to be carefully resolved.

  • Explained – SQL Injection, ASP.NET, ADO.NET:

http://msdn.microsoft.com/en-us/library/bb671351.aspx

Also, the above document contains a pointer to the following article “How To: Protect From SQL Injection in ASP.NET” http://msdn.microsoft.com/en-us/library/ms998271.aspx (which still applies to ASP)

A very useful video can be found here (this is the video refer on the previous article, but that link is currently broken): http://channel9.msdn.com/wiki/default.aspx/SecurityWiki.SQLInjectionLab

  • Generic information about how SQL Injection works:

http://msdn.microsoft.com/en-us/library/ms161953.aspx

  • SQL injections in ASP code (this is different from ASP.NET!):

http://msdn.microsoft.com/en-us/library/cc676512.aspx

How to call SQL Server stored procedures from ASP:

http://support.microsoft.com/kb/q164485

  • The Microsoft Security Development Lifecycle (SDL) has specific guidance to defend against SQL injection. In simple terms there are three different strategies to eradicate SQL Injection attacks:
      1. Using SQL parameterized queries

      2. Using stored procedures

      3. Using SQL execute-only permissions

Michael Howard covers those topics in http://blogs.msdn.com/sdl/archive/2008/05/15/giving-sql-injection-the-respect-it-deserves.aspx

Also, Writing Secure Code 2nd has good guidance on how to prevent these type of attacks as well (see pages 399-411)

  • SQL Injection Mitigation: Using Parameterized Queries (Part 1 & 2). The advantage of using parameterized queries is that it separates the executable code (ie, the SELECT statement) from the data (the dynamic information supplied by the application’s user). This approach prevents any malicious statements passed along by the user from executing.

Part 1: http://blogs.technet.com/neilcar/archive/2008/05/21/sql-injection-mitigation-using-parameterized-queries.aspx

Part 2: http://blogs.technet.com/neilcar/archive/2008/05/23/sql-injection-mitigation-using-parameterized-queries-part-2-types-and-recordsets.aspx

  • Filtering SQL injection form Classic ASP code (or blacklisting keywords), we considered the below as temporary workarounds since in reality it does not fix the root cause of the bugs (i.e. the code is still vulnerable and it might be reachable even after the filtering)

Nazim from the IIS team explains how to do the filtering in detail here: http://blogs.iis.net/nazim/archive/2008/04/28/filtering-sql-injection-from-classic-asp.aspx

If you are still not sure where to start, all web code that accesses a database with a particular focus on ASP code and areas of code which use user-supplied data should be review first.

 
End User Recommendations

End users should review the information at http://www.microsoft.com/protect/default.mspx; in addition, here are some specific steps that you can take to protect yourself.

  • As always, browse responsibly — but be aware that this could also affect websites that the user trusts

While responsible browsing limits your exposure to vulnerability, it is possible that even websites you trust may have been compromised. Watch for unusual behavior, be aware of the risk, and implement the other recommendations in this section.

  • Keep up to date on security updates, both Microsoft and 3rd party

Since the malicious scripts are exploiting known vulnerabilities, you should make sure that you are running the latest Microsoft and 3rd party security updates. Microsoft security updates are available via http://update.microsoft.com. Additional information is available at http://www.microsoft.com/protect/computer/updates/OS.aspx.

  • Disable unneeded ActiveX controls and Internet Explorer add-ons

You should disable any unneeded ActiveX controls and add-ons in Internet Explorer. To do this on Windows XP Service Pack 2 or later, follow these steps from KB883256 (http://support.microsoft.com/kb/883256):

1. Start Internet Explorer.
2. On the Tools menu, click Manage Add-ons.
3. Click the name of the add-on.
4. Use one of the following methods:
• Click Update ActiveX to replace the add-on with the current version. This option is not available for all add-ons.
• To enable an add-on, click Enable, and then click OK.
• To disable an add-on, click Disable, and then click OK.

You may have to restart Internet Explorer for the changes to take effect after you enable or disable an add-on.

For earlier operating systems, follow the instructions in KB154036 (http://support.microsoft.com/kb/154036).

  • Take steps to reduce attack surface of 3rd party browsers if you are using them

If you are using an Internet browser other than Internet Explorer, you should ensure that you have installed the latest security updates and that you disable unneeded extensions and add-ons. Information for popular browsers can be found at:

Firefox - http://support.mozilla.com/en-US/kb/Firefox+Support+Home+Page
Opera - http://www.opera.com/support/
Safari - http://www.apple.com/support/safari/

  • Run up-to-date anti-malware software

End users should ensure that they have anti-virus and anti-spyware software installed and that it is up to date. More information can be found at http://www.microsoft.com/protect/computer/antivirus/OS.aspx and http://www.microsoft.com/protect/computer/antispyware/OS.aspx. You can get a 90-day trial copy of Windows Live OneCare anti-virus/anti-spyware software at http://onecare.live.com/standard/en-us/install/install.htm.

- Security Vulnerability Research & Defense Bloggers

标签:

每个分类取最新的几条的SQL实现

分类统计时候,我们可能经常会碰到这样的需求,每个分类按照一定顺序,取几条数据,然后在一起显示。

这个问题的解决方法,我们通过搜索引擎,可以找到很多中。但是不是SQL语句过于复杂,就是在数据量比较大时候,性能特别成问题。

今天我就碰到这样一个需求。而我自己的解决方案就是SQL过于复杂,或者性能比较差的。为此我在CSDN论坛发了个帖子,看有没有更好的解决方案。

http://topic.csdn.net/u/20080504/14/5c5866c3-8b91-45ef-ab17-f994f88f8e42.html

CSDN的 SQL Server 板块  不愧是高手云集,问题发出不到半小时,就获得了近10种解决方案。经过测试,我把性能最高,且SQL不复杂的方案整理出来。特别感谢 jinjazz 的解答。

 

标签:

查询SQL连接数的方法

经常发生 “数据库连接过多的错误” 这样的错误,但是却又不清楚当前的连接数为多少,大致的总结了几种方法。1.通过系统的“性能”来查看:开始->管理工具->性能(或者是运行里面输入 mmc)然后通过 添加计数器添加 SQL 的常用统计 然后在下面列出的项目里面选择用户连接就可以时时查询到数据库的连接数了。

标签:

PowerDesigner Reports 排序问题

PowerDesigner生成report   结果那些表的顺序都是乱的,并非按照命名排列

解决方案:

右键Table %ITEM% ,selection,define  sort and Filter 属性窗口,将选择排序选择NAME字段,可实现左侧按表名排列

右键List of columns of the table %PARENT% ,selection,define  sort and Filter 属性窗口,将选择排序字段全部去掉,可实现表字段按默认顺序排列

标签:

MSSQL2005中的rowcount

据传SQL 2005有了RowID的东西,可以解决TOP排序的问题。可惜还没有机会体验。在SQL 2000中写存储过程,总会遇到需要TOP的地方,而一旦遇到TOP,因为没办法把TOP后面的数字作为变量写到预编译的语句中去,所以只能够使用构造SQL,使用Exec来执行。不说效率的问题,心里也总觉得这个办法很笨。

实际上,在SQL 2000中完全可以使用ROWCOUNT关键字解决这个问题。

ROWCOUNT关键字的用法在联机帮助中有比较详细的说明,这儿就不罗嗦了。谈谈体会。

1、使用ROWCOUNT查询前几行结果。

标签:

数据库中使用 Synonym和openquery

摘要:
如果,你想在一台数据库服务器上,查询另一个台数据服务器的数据该如何做呢?如果,你想在同一台数据服务器上,在不同的数据库之间查询数据,又该怎么办呢?那就让我为你介绍Synonym和openquery吧。

1, 什么是Synonym
Synonym(同义词)是Sql 2005的新特性。推出已经好几年了。你可以简单的理解Synonym 为其他表的别名。我们使用Northwind数据库为例。比如,看下面的例子

Create Synonym MyCustomers FOR Customers
为Customers表创建一个Synonym,叫MyCustomers。 你可以把这个MyCustomers当作一个普通的表,可以对它进行查询,更新,删除和插入。比如
查询: Select * from MyCustomers.
插入:  Insert into MyCustomers  (CustomersID, CompanyName) values ('Tom', 'MS')
所有的操作,和普通的表没有区别。

2, Synonym的应用
在你的程序发布的时候,你突然发现你需要更改某个表名,或字段名。而你的程序已经不可能修改。这时,怎么办呢?那就创建Synonym吧。当然,在sql2000时代,你可以使用view来做这个事情,或sprocs或udf等。但Synonym有其它所不能的功能,那就是跨数据库,跨服务器。

3,Synonym在同一服务器上的不同数据库
对于同一服务器上的不同数据库,我们可以使用Synonym,将其他数据库中的表或view或sprocs及udf在本数据库中映射别名。这样,就可以不用更改连接字符串,而在当前对话数据库的情况下,获取其他数据库的数据,并对它进行,查询,更新,删除和插入工作。
先假设已经存在Northwind数据库,然后,再建一个数据库。我们在新的数据库上,创建Customer表的Synonym.

Create Synonym MyCustomers For Northiwind.dbo.Customers 
需要注意的是,后面需要写清那个数据库,那个表,中间dbo为表的owner.
然后,运行 Insert into MyCustomers  (CustomersID, CompanyName) values ('Tom', 'MS')
和Select * from MyCustomers. 看看是不是真的像普通表那样。

4, Synonym在不同服务器上的不同数据库
假设,我们有一台数据库服务器叫SqlTest。上面有个数据库叫Northwind。我们本地还有一台数据库服务器。叫LocalTest. 其上面有一数据库叫Northwind或其他什么的。突然有一天,为了使本地的数据库跑的更快,本地的老数据被移到SqlTest上去了,本地只保存最近更新的。那老数据总还是要用的,怎么样实现不同服务器之间的数据操作呢?那就用Synonym吧。如下

Create Synonym MyCustomers For SqlTest.Northiwind.dbo.Customers 
在上一个例子的基础上,加了个机器名字而已。就这么简单?不是吧?那台服务器还不一定知道用户名和密码呢。恩,是的,还要在本地服务器上,注册下远程的服务器。使用sp_addlinkedserver,次存储过程定义如下:

sp_addlinkedserver [ @server = ] 'server'
    
[ , [ @srvproduct = ] 'product_name' ]
    [ , [ @provider = ] 'provider_name' ]
    [ , [ @datasrc = ] 'data_source' ]
    [ , [ @location = ] 'location' ]
    [ , [ @provstr = ] 'provider_string' ]
    [ , [ @catalog = ] 'catalog' ]
可以运行下面的脚本,将SqlTest注册到本地
EXEC sp_addlinkedserver
   @server = 'SqlTest',
   @provider = 'MSDASQL',
   @provstr = 'DRIVER={SQL Server};SERVER=SqlTest;UID=sa;PWD=;'
这样,就可以把远程数据库当成本地的来使用。

5,Synonym的其他功能和用UI创建Synonym
Synonym不光可以对表创建,也可以为view,sprocs,以及udf创建相应的Synonym. 如图:

Sql2005的Server Managerment Studio有这么一项,选择后,会出现下面画面。添入名称等,选择object的类型,你就可以选为View,Table, Sprocs和udf创建Synonym了。


6, openquery
相对于Synonym,OpenQuery相对来说,功能就弱了点。其只是在调用其它数据库上的sprocs.比如

select * from openquery([SqlTest]'exec northwind.dbo.[Customers By City] @param1=N''London'''where CustomerID = 'AROUT'


这就是在执行SqlTest服务器上的,northwind数据库下的,[Customers By City]的存储过程。你可以在
Linq To Sql进阶系列(五)Store Procedure篇 一文中,获得该存储过程。openquery其第一个参数为数据服务器的名称。如果是异地的,也需要在本地注册它,和Synonym相同。你也可以写本地的机器名,那就成了本地跨数据库的操作了。在上面的这个例子中,其语句中有London,是传入存储过程的值。因为其已经被 ' 引过,在openquery函数下,又要被 ' 引。所以,它两头加了两个 ''。 如果有疑问,请参阅SQL 语句中特殊字符的处理及预防sql 注射

7, Linq 对Synonym的支持
目前SqlMetal和OR designer无法对Synonym做映射。但是,用户依然可以通过手工修改dbml 达到映射的目的。Synonym在Linq中的使用。和其他表等没有任何差别。

结论:通过Synonym,我们可以实现不同数据库,以及不同服务器之间的数据分流。以达到平衡负载的目的,提高效率的目的。

参考文献:
sp_addlinkedserver  
SYNONYM in SQL Server 2005
How and why should I use SQL Server 2005 synonyms?
Using Synonyms in SQL Server 2005

标签:

优化SQL Server的内存占用之执行缓存

优化SQL Server的内存占用之执行缓存

 


 

在论坛上常见有朋友抱怨,说SQL Server太吃内存了。这里笔者根据经验简单介绍一下内存相关的调优知识。首先说明一下SQL Server内存占用由哪几部分组成。SQL Server占用的内存主要由三部分组成:数据缓存(Data Buffer)、执行缓存(Procedure Cache)、以及SQL Server引擎程序。SQL Server引擎程序所占用缓存一般相对变化不大,则我们进行内存调优的主要着眼点在数据缓存和执行缓存的控制上。本文主要介绍一下执行缓存的调优。数据缓存的调优将在另外的文章中介绍。


 

对于减少执行缓存的占用,主要可以通过使用参数化查询减少内存占用。

1、使用参数化查询减少执行缓存占用

我们通过如下例子来说明一下使用参数化查询对缓存占用的影响。为方便试验,我们使用了一台没有其它负载的SQL Server进行如下实验。

下面的脚本循环执行一个简单的查询,共执行10000次。


 

首先,我们清空一下SQL Server已经占用的缓存:

dbcc freeproccache


标签:

分页:«12345678»