C#连接SQL Anywhere 12 数据库

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();
        }
    }
}

posted @ 2014-09-06 16:51  TonysDad  阅读(1242)  评论(0编辑  收藏  举报