C#连接各种数据库

    这次做一个项目。用c#连接各种各样的数据库。为了连接数据库,我一个一个的做测试。后来发现是一篇连接数据库的文章。既然如此,我就写在博客上了。

首先,连接sqlsever2000


            SqlConnection thisConnection 
=   new  SqlConnection( @" Server=127.0.0.1;uid=sa;pwd=123;database=Test " );
            thisConnection.Open();

            
// create commond for this connection
            SqlCommand thisCommand  =  thisConnection.CreateCommand();
            thisCommand.CommandText 
=   " select * from USER_ACCOUNT " ;

            
// excute
            SqlDataReader thisReader  =  thisCommand.ExecuteReader();

            
// output
             while  (thisReader.Read())
            
{
                Console.WriteLine(
" {0} {1} {2} {3}", thisReader[0], thisReader[1], thisReader[2], thisReader[3]);
            }


            
// close
            thisReader.Close();
            thisConnection.Close();

其次,就是SQLExpress

 

             连接SQLEXPRESS

在这里,要特别注意这句:Integrated Security=SSPI。如果不加这句,sa的验证是通不过的,不知道为什么,经验而已。

还有连接Oracle和MySql的,明天再写。还有用Ibatis的。改日再写。

你可能感兴趣的:(早期文章)