<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Edi Wang</title><description>Microsoft MVP for Azure</description><link>https://edi.wang/</link><pubDate>2026-04-13T09:02:16Z</pubDate><copyright>© 2009 - 2026 edi.wang</copyright><generator>Moonglade v15.13.1</generator><language>en-US</language><item><title>PowerShell to Enable SQL Server Express Remote Access</title><link>https://edi.wang/post/2024/1/18/powershell-to-enable-sql-server-express-remote-access</link><description>SQL Server Express is a free edition of Microsoft's SQL Server, which is a relational database management system (RDBMS). However, remote access is not enabled by default on this SKU. To access a SQL Server Express instance from the network, we have to do a few steps. There's plenty of guide on the internet telling you how to enable remote access via GUI, but I would like to do it from PowerShell. …</description><category>Server and Tools</category><category>Data Platform</category><guid isPermaLink="false">94754AF1-8CF2-4600-A4D7-BAB8DC0DF76D</guid><pubDate>2024-01-18T05:52:41Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2024-01-18T05:52:41Z</updated></item><item><title>Import Data to Azure Storage Table from SQL Server</title><link>https://edi.wang/post/2020/6/11/import-data-to-azure-storage-table-from-sql-server</link><description>Recently, there was a demand to switch data storage from SQL Server database to Azure Storage Table. However, neither SSMS nor Azure Portal provide a direct import function. You may now consider writing a tool to import data, but actually it isn't necessary. I still managed to do it within mouse clicks. But the first thing to warn everyone is that relational databases like SQL Server are not …</description><category>Microsoft Azure</category><category>Data Platform</category><guid isPermaLink="false">417990E3-46C3-4CB3-957D-FA264FA457A3</guid><pubDate>2020-06-11T06:46:24Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2020-06-11T06:46:24Z</updated></item><item><title>SQL Server Export Data Tier Application via Command Line</title><link>https://edi.wang/post/2019/5/20/sql-server-export-data-tier-application-via-command-line</link><description>We can use SSMS to export data-tier application for an SQL Server database. I've been using this method for several years on my local machine.  However, to make things work under automated environments, like CI/CD environments, or some automated scheduled tasks. We usually need to do it under the command line.  Microsoft has provided a cross-platform command-line tool that can import/export DAC: …</description><category>Data Platform</category><guid isPermaLink="false">359CE8A5-3DFD-4CF6-B0C0-274A96D73EBD</guid><pubDate>2019-05-20T02:08:13Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2019-05-20T02:08:13Z</updated></item><item><title>Merge Data for N-N Relationship Tables in T-SQL</title><link>https://edi.wang/post/2017/1/29/t-sql-merge-data-n-n</link><description>Recently, I have been organizing my blog data and needed to perform an operation to merge article categories. On my blog, articles and categories have a many-to-many relationship. That is, one article can belong to multiple categories, and one category can contain multiple articles. This is a very typical many-to-many relationship, and I use a many-to-many table with a composite primary key to associate this data. What I need to do is move articles from the "DotNetBeginner" category to the "CSharpAndDotNet" category. However, since some of the articles originally in the "DotNetBeginner" category also belong to "CSharpAndDotNet", directly updating the association table would result in duplicate composite keys, which would cause issues.</description><category>Data Platform</category><guid isPermaLink="false">BC03035A-3FA1-477A-B4D8-460D5992C8DD</guid><pubDate>2017-01-29T03:32:12Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2017-01-29T03:32:12Z</updated></item><item><title>Azure SQL数据库Web Tier爆了，如何迁移数据库</title><link>https://edi.wang/post/2015/3/22/how-to-migrate-azure-sql-db-web-tier-blow-up</link><description>今天做了次数据库迁移，目的是开个最新版的Azure SQL Database（V12 Update），然后把博客的数据库迁移到新的server上去。按以往的做法（也就是我曾经写过的《图解：如何将SQL Server数据库迁移到SQL Azure 》），把bacpac文件下载下来，然后import到新的数据里，结果爆了：  爆炸是因为Web Tier和Business Tier在最新版的Azure上面已经被微软撸掉了，SSMS 2014却没有升级，不认识这两个Tier，还在用老的Web Tier。 TITLE: Microsoft SQL Server Management Studio ------------------------------ An exception occurred while executing a Transact-SQL statement or batch.</description><category>Microsoft Azure</category><category>Data Platform</category><guid isPermaLink="false">B8277631-689E-41B3-8B9F-BD89202AAACB</guid><pubDate>2015-03-22T04:00:10Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2015-03-22T04:00:10Z</updated></item><item><title>EntityFramework 6 SqlQuery Passes Nullable Type Arguments</title><link>https://edi.wang/post/2014/9/3/pass-nullable-value-to-sqlquery-t-ef6</link><description>有时候我们需要在EF里直接执行参数化的SQL语句，如果有返回，就要把结果映射成C#对象集合。貌似是从EF4.2开始（4.0写法不一样）提供了DbContext.Database.SqlQuery()的API可以直接执行SQL。但是如果碰到可控类型的参数，比如Guid?，就会爆。  看一个例子，定义的SQL语句如下： string sql = @"SELECT p2.Id                      AS PeriodId,                       p2.Title                   AS PeriodTitle,                       u.UserId                   AS UserId,                       u.DisplayName              AS</description><category>Data Platform</category><guid isPermaLink="false">17FA3A86-6578-4565-AF54-C62C2EF86045</guid><pubDate>2014-09-03T01:38:23Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2014-09-03T01:38:23Z</updated></item><item><title>EntityFramework中使用.Include()做饥饿加载可能产生的性能问题</title><link>https://edi.wang/post/2013/10/4/eagerly-loading-using-include-entityframework-performance</link><description>这几天在码新版博客程序，因为文章表字段太多，手贱把几个相关列拆分到了1-1的表中。比如Post 1-1 PostPublish，Post 1-1 PostExtension。但是性能突然比以前差了一点。 和这两张相关表直接交互的是这么一段代码： var query = Repository.Select().Include(p =&gt; p.PostExtension).Include(p =&gt; p.PostPublish)                       .Where(p =&gt; p.PostPublish.IsPublished &amp;&amp;                                   (authorName == null ||                                   String.Compare(p.Author, …</description><category>Data Platform</category><guid isPermaLink="false">A184EDDA-04FC-43AF-A960-5232F63909A2</guid><pubDate>2013-10-04T01:25:44Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2013-10-04T01:25:44Z</updated></item><item><title>图解：如何将SQL Azure数据库备份到本地SQL Server</title><link>https://edi.wang/post/2013/4/29/backup-sql-azure-to-sql-server</link><description>用了两天SQL Azure后，发现SQL Azure数据库没有办法做传统意义上的“bak”备份，但我们确实很需要能够随时将数据库备份到本地，以更灵活的使用。所以今天就开荒了一下操作方法，并分享给大家。这样一来，我们既可以把SQL Server迁移到SQL Azure，又可以反过来把SQL Azure撸回SQL Server，这是一个比较完整的装逼过程，妹子们一定会赞不绝口。 步骤如下： 1. 启动SSMS2012，在目标SQL Azure数据库上点右键，选择“Export Data-tier Application”。  2. 在Export Settings选项卡里制定本地的备份路径，现在已经是“bacpac”拓展名的了。。。  3. 然后点击Next，确认后就向导就开始撸了。  4. 撸完以后会显示Operation Complete的消息，现在本地备份文件已经创建完成了。  5. 在 …</description><category>Microsoft Azure</category><category>Data Platform</category><guid isPermaLink="false">5211350E-7F72-48CD-9BFD-8F557CB7FC8D</guid><pubDate>2013-04-29T13:04:07Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2013-04-29T13:04:07Z</updated></item><item><title>图解：如何将SQL Server数据库迁移到SQL Azure</title><link>https://edi.wang/post/2013/4/28/migrate-sql-server-to-sql-azure</link><description>最近为了进一步装逼，决定将本博客的数据库从SQL Server 2008 R2迁移到Windows Azure上，即SQL Azure，云数据库。今天花了半天时间成功完成了迁移，把经验拿出来给大家分享。 注意：本文的方法只在SQL Server 2008 R2和SQL Server 2012数据库上试过，其他版本生死未卜。 首先，不管你现在的数据库是MSSQL2008R2的还是MSSQL2012的，你都需要安装SQL Server 2012版的SSMS。这是最方便的迁移方法。如果不想用SSMS，可以试试codeplex上的这个工具：http://sqlazuremw.codeplex.com/ 1. 启动SSMS后，在要被迁移的本地数据库上点右键，选择Tasks - Deploy Database to SQL Azure...  2. 在弹出的向导中，点击Connect，连接到你在 …</description><category>Microsoft Azure</category><category>Data Platform</category><guid isPermaLink="false">38E1BE75-BD92-48FA-B887-183F41D22A71</guid><pubDate>2013-04-28T12:52:13Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2013-04-28T12:52:13Z</updated></item><item><title>Performance tips for Entity Framework</title><link>https://edi.wang/post/2012/12/9/performance-tips-for-entity-framework</link><description>自从我用了EF，每次都很关心是否有潜在的性能问题。所以每次我写LINQ查询，都会使用SQL Profiler看一下实际生成的SQL语句，以便发现潜在的性能问题。也强烈建议大家这么去做，以免日后软件大了出了问题很难查。 一、只选择某列或某些列 有些时候，在C#里写LINQ虽然看着舒服，但性能不一定好，所以有必要做一些调整。比如这种情况： 我需要知道一篇文章的点击数，仅此而已，我可能会写： context.Post.FirstOrDefault(p =&gt; p.Id == postId).Hits; 或者： context.Post.Find(postId).Hits; 我期待着他们只去数据库里筛选Hits这一列的数据，然而，通过SQL Profiler会发现，这两条语句居然把全部列都给select出来了，访问Hits的操作实际是在内存中进行的。 虽然小表看不出性能问题，但万一你的表里有一列是存 …</description><category>.NET</category><category>Data Platform</category><guid isPermaLink="false">BD4C176F-6242-438C-993F-17B287D0F0BA</guid><pubDate>2012-12-09T11:10:07Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-12-09T11:10:07Z</updated></item><item><title>How to Manually Upgrade Entity Framework 4.0 to 5.0</title><link>https://edi.wang/post/2012/12/1/manually-upgrade-entityframework-from-40-to-50</link><description>I have been working on the next version of my blog recently, and one of the updates is upgrading Entity Framework to version 5.0. When I initially set up the blog, I used EF4 that came with VS2010. The upgrade process from version 4.0 has to be done manually; using NuGet for the upgrade can only automatically update to versions 4.1 and above. Yesterday, I worked on it for a long time, and finally got the website up and running. Here's what I learned from the experience.</description><category>.NET</category><category>Data Platform</category><guid isPermaLink="false">255FA220-E7B0-4312-A90B-C0AED908D6FA</guid><pubDate>2012-12-01T00:41:59Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-12-01T00:41:59Z</updated></item><item><title>给ASP.NET Membership增加权限（Rights）功能</title><link>https://edi.wang/post/2012/11/9/add-rights-to-aspnet-membership</link><description>首先说明，本文用的是非常屌丝的办法，针对SQL Server Membership的实现的一个很有局限性的权限模块，而不是真正对ASP.NET Membership本身的拓展。不喜慎入。 一、为什么要给Memebership增加权限系统 我们知道，ASP.NET Membership是基于Role的，其实是个RBAC，没有权限（Rights）功能。也就是说，我们只能够指定某个Role可以做什么事，丧失了一定的灵活性。比如，网站后台有个编辑文章的功能。如果基于Role判断，我只能认为：所有Admin、Editor、Teacher可以编辑文章。在MVC3里，可以用Authorize(Role=”Admin, Editor, Teacher”)的属性做到这一点。然而如果想要动态可配，则比较难了。然而，如果是基于Rights的验证，那我就可以认为：所有具有Edit权限的Role可以编辑文章。这样的 …</description><category>.NET</category><category>Data Platform</category><guid isPermaLink="false">01DF13B4-31C4-4A8E-8215-A2D266088850</guid><pubDate>2012-11-09T02:26:26Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-11-09T02:26:26Z</updated></item><item><title>在Entity Framework中使用LINQ语句分页</title><link>https://edi.wang/post/2012/9/21/linq-paging-in-entity-framework</link><description>我们知道，内存分页效率很低。并且，如果是WebForm的项目，页面上会有巨型ViewState，这必然不好。我自己博客用的是一个存储过程做的分页，用到现在都挺好，没有任何效率问题。后来想到，既然项目里有Entity Framework，那为什么不利用EF完成分页呢～ 稍做研究之后发现，EF分页其实很简单。不过一样写文章了，光贴代码是不负责的，还是得稍微介绍一下相关的知识。 一、页数计算 关于分页的基本原理，网上有很多文章，我就不多叙述了。但我发现很多介绍分页的文章里，计算页码公式都掐掉了，广为流传的版本是： totalPage = totalRecord / pageSize + 1 稍微推敲一下就会发现，这个公式在totalRecord和pageSize正好整除时，会多一页。比如10条记录，每页5条，应该是2页的，但结果是3。然而，不写+1又不行，因为要考虑到记录总数小于页尺寸的情况。现 …</description><category>Data Platform</category><guid isPermaLink="false">40AE6109-EE62-4CAB-A015-27F6CCF38E27</guid><pubDate>2012-09-21T07:31:13Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-09-21T07:31:13Z</updated></item><item><title>Store and Read Images via SQL Server in ASP.NET MVC 3</title><link>https://edi.wang/post/2012/9/20/store-and-read-images-via-sql-server-in-aspnet-mvc-3</link><description>First of all, I don't recommend storing images in the database, especially in a web project. Because file systems can provide static file access and get many benefits such as performance. Storing images in the database has certain limits.
But if you must store images into SQL Server, here's how to do it. 
SQL

Image files are in fact, binary data. SQL Server provides us the image type for …</description><category>.NET</category><category>Data Platform</category><guid isPermaLink="false">1C7AE284-121C-45DF-B25B-53A0BF7039F6</guid><pubDate>2012-09-20T12:16:27Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-09-20T12:16:27Z</updated></item><item><title>博客数据库升级手记（四）：XML数据的导入</title><link>https://edi.wang/post/2012/8/27/blog-db-update-4-import-xml-data</link><description>在上一篇文章中，我已经完成了旧数据库的导入。然而，我的博客原先除了用Access数据库保存数据，也大量使用了XML存储，这借鉴自BlogEngine.NET，但后来发现XML存储弊大于利，最适合我的还是传统关系型数据库。因此，我有必要把所有非系统数据迁移到SQL Server上。这里要提一句，系统数据和用户数据是不一样的。系统数据是维持系统程序的运行所需要的数据，用户数据是用户使用系统产生的数据。系统数据包括系统设置（XML保存）、系统菜单等等，而用户数据除了博客文章，还有其创建的页面、友情链接，这些东西原先都是XML存储的，这次要统一迁移到SQL Server上。 首先，要对应XML的数据结构，在SQL Server中建立对应的表，列名和数据类型可以不一样，但要记得方便导入，不然就得用前几篇文章的技巧处理了。本文以友情链接表为例，建立的表如下： CREATE TABLE [dbo].[ …</description><category>Data Platform</category><guid isPermaLink="false">D9CF98EF-7CB8-44F4-872B-E814E13B7620</guid><pubDate>2012-08-27T23:28:02Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-08-27T23:28:02Z</updated></item><item><title>博客数据库升级手记（三）：标签库的导入</title><link>https://edi.wang/post/2012/8/26/blog-db-update-3-import-tag-library</link><description>上篇文章留下了一个话题，关于标签库的导入。因为设计的变化，标签库无法从Keywords字段中直接导了。
首先，分析一下新表的结构。Tag表是用来保存所有标签的。Tag.Id是uniqueidentifier类型的主键，它将被PostTag表关联，来描述多对多的结构。Tag.Name是标签名称。这是可以从老数据的Blog.Keywords字段中获得的。
所以，第一步，是要从Keywords字段提取信息，插入到Tag表中。随后再处理关联问题。
老数据库里的Keywords字段中保存的，是以英文逗号分隔的文章标签。比如“ASP.NET,CSS,HTML”就表示这篇文章拥有3个标签，分别是ASP.NET、CSS和HTML。首先，我需要解析原先的Keywords字符串，将以逗号分隔的内容解析出来。但SQL Server没有提供Split函数，所以需要自己写一个：
CREATE …</description><category>Data Platform</category><guid isPermaLink="false">DDAD0463-69F8-49E0-90EF-A4E410098D8F</guid><pubDate>2012-08-26T23:05:02Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-08-26T23:05:02Z</updated></item><item><title>博客数据库升级手记（二）：新数据库的建立及简单数据的导入</title><link>https://edi.wang/post/2012/8/26/blog-db-update-2-new-db-and-simple-data-import</link><description>前面一片文章讲了如何将Access数据库直接导入SQL Server。但导入完成后，是强烈建议不要使用的。因为里面的object命名都与sql默认的不符，许多T-SQL行为也很诡异，所以我需要重新建立一个数据库，并且把旧的数据导入到新的数据库中。 新数据库的设计 对于新的数据库，这恰好是一次重构和升级的机会，我可以将4年前不合理的表结构设计重构一下（4年前也就是我第一次做这个博客的时候，菜鸟一只）。新的数据库中，博客子系统的设计如下（其实还有很多别的表，但不是给博客主业务用的，以后再讨论）：  而旧数据库仅仅只有3张表：Blog、Category、Comment。 对于Category，没有太大的改动，仅仅是增加一个”Name”字段，用来做MVC的路由，而”DisplayName”的功能则和原先数据库是一样的，表示这个分类在页面上显示的名称。 Comment表增加了Email字段，是可选的 …</description><category>Data Platform</category><guid isPermaLink="false">3D666776-6D6C-49AC-B548-905BDA8C42CB</guid><pubDate>2012-08-26T01:57:35Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-08-26T01:57:35Z</updated></item><item><title>博客数据库升级手记（一）：将Access数据库迁移到SQL Server</title><link>https://edi.wang/post/2012/8/13/blog-db-update-1-access-to-sqlserver</link><description>本人使用的网站空间送了个200M的SQL Server2008 R2数据库，我不用白不用。所以上周花了很多时间把网站从Access和XML数据存储上迁移到了SQL Server数据库，顺便也升级了一下架构，目前博客子系统已基本完成迁移，最近将逐个迁移页面集系统、留言等模块。 在迁移的过程中，有许多值得记录的经验，在实际项目中非常实用，所以记录下来以备参考。 首先，我的迁移思路是：数据的迁移尽量不通过程序去做，应当采用SQL Server去实现。那么第一步我就得把Access数据库迁移到SQL Server上，这样才能在SQL Server中进行一致的管理和迁移到新的数据库上。 我原来的数据库是Access2007格式的（格式没有太大的关系，2003也可以这样操作）。在Access 2010中的操作方法如下： 1. 在Database Tools选项卡下选择“SQL Server”：  2. …</description><category>Data Platform</category><guid isPermaLink="false">ED6F3726-F60B-4BC6-BD81-F7E611BA98F7</guid><pubDate>2012-08-13T05:02:53Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-08-13T05:02:53Z</updated></item><item><title>在SQL Server完整版上部署ASP.NET Membership</title><link>https://edi.wang/post/2012/7/26/deploy-aspnet-membership-on-sqlserver-full-version</link><description>平时做练习的时候，用的Membership虽然是SQL方式的，但版本是SQL Express，连接的是网站App_Data文件夹里的mdf文件。如果要把同样的Membership部署到SQL完整版上是会爆的。比如你开发的时候自己用的Express，部署到你的主机服务商时，人家当然用的付费购买的完整版。这样就会爆。网上查了些资料，说Membership是SQL Express独有的功能，我不相信。所以自己开荒了一下，并且成功了。分享给大家。 首先，连接网站App_Data目录的mdf文件，确实只有Express版可以。所以完整版的SQL Server必须在数据库引擎里建立数据库，不要放在网站目录下。 建完数据库以后，打开VS2010的命令行环境，运行aspnet_regsql，你会看到下面这个界面。  选择第一项，即在SQL Server里配置Application Services，然后点</description><category>.NET</category><category>Data Platform</category><guid isPermaLink="false">79DBBC00-115D-4CA0-B249-4D5418B65287</guid><pubDate>2012-07-26T02:32:34Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2012-07-26T02:32:34Z</updated></item><item><title>浅谈SQL注入攻击与防范</title><link>https://edi.wang/post/2010/10/1/attack-and-prevent-of-sql-injection</link><description>前置知识：数据库、SQL语句、Web编程(ASP、ASP.NET) 前言：这次要谈到问题，其实不是什么新鲜的内容了，早在许多年前，就在各种黑客杂志和网站上提及过。这次我重新谈起这个问题，一方面是为了完成作业，另一方面我会结合目前的前沿技术来谈谈在SQL注入方面的新进展和防范。希望大家能以技术学习为目的，不要利用SQL注入漏洞进行非法攻击。  一、SQL注入漏洞是如何产生的 我们知道，一个动态网站，往往是要和数据库紧密交互的，即按条件从数据库中取出数据在网页上送显，或按用户的操作去改变数据库中的内容。最普遍的应该是新闻系统。我们经常在地址栏看形如这样的URL：http://某网站/ReadNews.asp?id=32，这个URL的作用是把ID=32传给 ReadNews.asp，ReadNews接受到这个id后，就会到数据库中找到id为32的新闻，取出这条记录并将它显示在网页上。然而，这样真 …</description><category>Data Platform</category><guid isPermaLink="false">83BE89E4-F983-4EAE-8CE6-48841F4F5786</guid><pubDate>2010-10-01T00:53:57Z</pubDate><updated xmlns="http://www.w3.org/2005/Atom">2010-10-01T00:53:57Z</updated></item></channel></rss>