Visual Studio 2008初试

  早先就听说微软推出了visual Studio 2008的测试版,但一直没有碍于下载速度和出于对2005的习惯,未得一试,只到前两天布署上Sql server 2005,才将这个庞然大物拉下来。
   安装一如从前的便捷,界面上有了改进,更炫,付出的代价是速度更慢。


 
  前端页面的编辑视图栏里,增加了“拆分”视图,有如Dreamweaver,从此不必假其他工具而“立改立见”
 
  内置Ajax Extensions工具集,正好一试,以前用Anthem和prototype比较多

  内置对dot net Framework 3.5的支持,轻松创建WPF程序

  内置代码测试和性能分析工具


  新功能方面有待摸索,目前最感兴趣的是与数据库的集成开发,做一个小用例测试一下Sql CLR存储过程重复插入数据性能:

  在DB中,存在表 TB_COUNTRY,结构如:
 

  创建一Sql Server CLR项目,并为其添加存储过程AddCountryMillons,实现重复插入百W记录,结束时返回统计用时长度:

using  System;
using  System.Data;
using  System.Data.SqlClient;
using  System.Data.SqlTypes;
using  Microsoft.SqlServer.Server;

public  partial  class  CountryProc
{
    
/**//// <summary>
    
/// 连接串
    
/// </summary>

    public const string CONN_MOYE2005_STRING = @"Data Source=ZHANGCHI\MOYE2005;Initial Catalog=Indie;User Id=sa;Password=system;";
    
    
/**//// <summary>
    
/// 插入百万条记录,返回用时(秒数)
    
/// </summary>

    [Microsoft.SqlServer.Server.SqlProcedure]
    
public static int AddCountryMillons(string EName, string CName)
    
{
        
if (EName.Trim() == string.Empty || CName.Trim() == string.Empty)
        
{
            
return 0;
        }


        
using (SqlConnection conn = new SqlConnection(CONN_MOYE2005_STRING))
        
{
            
try
            
{
                conn.Open();
                
// insert a record
                SqlCommand cmd = new SqlCommand(
                    
string.Format("INSERT INTO TB_COUNTRY(CountryEName,CountryName) VALUES('{0}','{1}')",
                        EName, CName),
                    conn);
                
// excute millons                
                TimeSpan span = TimeSpan.Zero;
                DateTime begin 
= DateTime.Now;

                
for (int i = 0; i < 1000000; i++)
                
{
                    cmd.ExecuteNonQuery();
                }

                DateTime done 
= DateTime.Now;
                span 
= done - begin;
                
return Convert.ToInt32(span.TotalSeconds);
            }

            
catch (Exception err)
            
{
                
return -1;
            }

            
finally
            
{
                conn.Close();
            }

        }

    }

}
;

  创建Web项目,添加对SQL CLR项目的引用,制作页面并最终显示执行的时长
   由于存储过程插入数据量大,为不出现阻塞现象,在此使用“委托异步回调+Ajax客户端”方式呈现结果

  页面结构如下
<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeBehind = " Default.aspx.cs "  Inherits = " Vs2008_Project._Default "  StylesheetTheme = " Home "   %>
<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml "   >
< head runat = " server " >
    
< title > visual Studio  2008  Demo </ title >
</ head >
< body >
    
< form id = " form1 "  runat = " server " >
    
< div >     
        国家中文名称:
< asp:TextBox ID = " txtCName "  runat = " server " ></ asp:TextBox >
        
< br  />
        国家英文名称:
< asp:TextBox ID = " txtEName "  runat = " server " ></ asp:TextBox >     
        
< br  />
        
< div >
            
< asp:ScriptManager ID = " ScriptManager1 "  runat = " server " >         
            
</ asp:ScriptManager >
        
</ div >         
        
< asp:UpdatePanel ID = " UpdatePanel1 "  runat = " server "  RenderMode = " Block " >
            
< ContentTemplate >
            
< ul >
                
< li >
                    
< asp:Label ID = " lblRes "  runat = " server "  Text = " Label " ></ asp:Label >
                
</ li >
                
< li >
                    
< asp:Button ID = " btAdd "  runat = " server "  Text = " 执行插入 "  onclick = " btAdd_Click "   />
                
</ li >
            
</ ul >     
            
</ ContentTemplate >                         
        
</ asp:UpdatePanel >         
</ div >
</ form >
</ body >
</ html >

后端代码:
using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Linq;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

using  System.Threading;

namespace  Vs2008_Project
{
    
public partial class _Default : System.Web.UI.Page
    
{
        
/**//// <summary>
        
/// 异步委托插入数据
        
/// </summary>

        public delegate int AsynInsertMillonData();

        
protected void Page_Load(object sender, EventArgs e)
        
{

        }


        
/**//// <summary>
        
/// 开始调用
        
/// </summary>        

        protected void btAdd_Click(object sender, EventArgs e)
        
{
            
// 异步回调方法
            AsyncCallback callback = new AsyncCallback(AsynDone);
            
// 委托实例
            AsynInsertMillonData aimd = new AsynInsertMillonData(InsertMillion);
            
// 开始调用
            IAsyncResult ar = aimd.BeginInvoke(callback, aimd);
        }


        
/**//// <summary>
        
/// 异步执行完成
        
/// </summary>        

        public void AsynDone(IAsyncResult ar)
        
{
            AsynInsertMillonData aimd 
= (AsynInsertMillonData)ar.AsyncState;
            
int result = aimd.EndInvoke(ar);
            ShowResult(result);
        }


        
/**//// <summary>
        
/// 插入百万条数据
        
/// </summary>
        
/// <returns>状态值OR插入时间</returns>

        public int InsertMillion()
        
{
            
// CALL STORE PROCEDURE
            return CountryProc.AddCountryMillons(this.txtEName.Text, this.txtCName.Text);
        }


        
/**//// <summary>
        
/// 显示执行结果
        
/// </summary>        

        private void ShowResult(int res)
        
{            
            
if (res > 0)
            
{
                SetPannelText(
string.Format("添加成功!耗时{0}秒", res));
            }

            
else if (res == 0)
            
{
                SetPannelText(
"输入空值不执行!");
            }

            
else
            
{
                SetPannelText(
"添加失败!");
            }

        }


        
/**//// <summary>
        
/// 更新PANNEL内的文本
        
/// </summary>

        private void SetPannelText(string text)
        
{            
            lblRes.Text 
= text;           
        }

    }

}

  经过几次测试,平均值总在520-540秒之间, 不乐观~虽然不清楚这个SQL CLR是怎么一个运行原理,但
用代码或者O/R Mapping框架取代DB内置的存储过程在短期内是没什么指望了,虽然我很喜欢那么干

转载于:https://www.cnblogs.com/moye/archive/2007/09/25/905510.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值