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();
}
}
}
相关文章
- 01-13C# EF 加密连接数据库连接字符串
- 01-13基于SpringBoot的sql项目环境配置及连接数据库
- 01-13go连接数据库并执行文件中的sql语句
- 01-13C#反射在数据库连接时的应用
- 01-13c# – log4net – 连接断开后如何重新建立与数据库的连接
- 01-13数据库连接报错 The server seelcted protocol version TLS10 is not accepted by client preferences[TLS13,TLS12
- 01-13C# 读取 appconfig文件配置数据库连接字符串,和配置文件
- 01-13C# 数据库连接-连接字符串
- 01-13C# SQL数据库助手类2.0(自用)
- 01-13C# 还原SQL数据库(非存储过程方式)