日期:2014-05-18  浏览次数:20770 次

很简单的ado.net连接sql数据库问题数据库,请高手帮下
我是单机的  
sql   server2005中  
服务器   COMPUTER\SQLEXPRESS  
用户名   eric  
请高手帮帮我   谢谢
我用windows验证连接,可是怎么也连不上??请高手帮下

using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Text;
using   System.Windows.Forms;
using   System.Data.SqlClient;
using   System.Data;

namespace   WindowsApplication1
{
        public   partial   class   Form1   :   Form
        {
                public   Form1()
                {
                        InitializeComponent();

                }

                private   void   Form1_Click(object   sender,   EventArgs   e)
                {
                      /*   Form2   frm2   =   new   Form2();
                        frm2.MdiParent   =   this;
                        frm2.Show();
                        */
                }

                private   void   InitalizeToolStripMenuItem_Click(object   sender,   EventArgs   e)
                {
                        try
                        {
                                SqlConnection   con   =   new   SqlConnection( "server=localhost;Integrated   Security=SSPI ");  
                                con.Open();
                                SqlCommand   cmd   =   new   SqlCommand();
                                cmd.Connection   =   con;
                                cmd.CommandText   =   "create   database   Flight ";
                                cmd.ExecuteNonQuery();
                                cmd.CommandText   =   "use   Flight ";
                                cmd.ExecuteNonQuery();