码迷,mamicode.com
首页 > 数据库 > 详细

C#连接SQL Anywhere 12 数据库

时间:2014-09-06 17:22:23      阅读:461      评论:0      收藏:0      [点我收藏+]

标签:os   io   ar   数据   cti   sp   on   c   line   

using System;
using System.Data.Common;

namespace ConsoleApplication27
{
    class Program
    {
        static void Main(string[] args)
        {
            DbProviderFactory dbFactory = DbProviderFactories.GetFactory("iAnywhere.Data.SQLAnywhere");
            DbConnection dbconn = dbFactory.CreateConnection();

            try
            {
                dbconn.ConnectionString = "User ID=dba;Password=sql;DataSourceName=\"SQL Anywhere 12 Demo\"";
                dbconn.Open();

                if (dbconn.State == System.Data.ConnectionState.Open)
                {
                    Console.WriteLine("Connection is Open!");

                    dbconn.Close();
                    if (dbconn.State == System.Data.ConnectionState.Closed)
                        Console.WriteLine("Connection is Closed!");
                }
            }
            catch (DbException dbexception)
            {
                Console.WriteLine(dbexception.Message);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            Console.ReadKey();
        }
    }
}

C#连接SQL Anywhere 12 数据库

标签:os   io   ar   数据   cti   sp   on   c   line   

原文地址:http://www.cnblogs.com/bisslot/p/3959566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!