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