连接SQLServer OLEDB数据库(ACCESS) ODBC Oracle
web.Config文件中的连接字符串
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/> </system.web>
<appSettings>
<add key="conStr" value="Server=.;User Id=sa;Pwd=123456;DataBase=master"/>
</appSettings>
</configuration>
页面加载代码:
protected void Page_Load(object sender, EventArgs e)
{
// string sqlStr=ConfigurationSettings.AppSettings["conStr"];
string sqlStr = ConfigurationManager.AppSettings["conStr"];
SqlConnection con = new SqlConnection(sqlStr);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
Response.Write("数据库连接成功");
con.Close();
}
else if (con.State == System.Data.ConnectionState.Closed)
{
Response.Write("数据库关闭!");
}
}
连接OLEDB数据库是Access的,代码如下::
protected void Page_Load(object sender, EventArgs e)
{
string strLoad = Server.MapPath("~/App_Data/Access.mdb");
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strLoad);
myConn.Open();
if (myConn.State == System.Data.ConnectionState.Open)
{
Response.Write("ACCESS数据库打开!");
myConn.Close();
}
else if (myConn.State == System.Data.ConnectionState.Closed)
{
Response.Write("ACCESS数据库关闭!");
myConn.Close();
}
}
直接在 控制面板---管理工具----数据源(ODBC) 打开数据源配置,发现只有SQLServer的驱动,其他的都没有了。
解决方法是:
C:\Windows\SysWOW64
在这个目录下找到:
odbcad32.exe
这个文件,双击打开。
里面有很多可用个数据源驱动,然后就可用添加连接Access的ODBC的数据源了
使用OdbcConnection对象连接ODBC数据源 string strCon = "Driver=数据库提供程序名;Server=数据库服务名;Trusted_Connection=yes;Database=数据库名;";
odbcconn.Open();
odbcconn.Close();
使用Oracle 数据库 string strCon = "Data Source=Oracle8i; Integrated Security=yes"; OracleConnection oracleconn=new OracleConnection(strCon) ; odbcconn.Open();
odbcconn.Close();
连接SQLServer OLEDB数据库(ACCESS) ODBC Oracle的更多相关文章
- Java连接SqlServer 2008数据库
将sqljdbc4.jar包添加到工程 连接SqlServer 2008数据库 import java.sql.Connection; import java.sql.DriverManager; i ...
- Php5.6.31连接sqlserver 2008R2数据库问题sqlsrv(php5.3及以上版本)与mssql(php5.3以前版本)②
Php5.6.31连接sqlserver 2008R2数据库 1.环境配置 Win7(win8.1) 64 +Apache2.4 + PHP5.6.31 + SQL Server 2008 R2数据 ...
- 【JSP动态网站】JDBC连接SqlServer 2008数据库
JSP程序需要通过JDBC接口才能访问数据库. 启动MyEclipse,选择“Window”→“Open Perspective”→“MyEclipse Database Explorer”菜单项,打 ...
- Java使用JDBC连接随意类型数据库(mysql oracle。。)
package cn.liz.test; import java.io.InputStream; import java.sql.Connection; import java.sql.Driver; ...
- Springboot整合Mybatis,连接多个数据库(Mysql+Oracle)
maven依赖,需要注意的是mysql使用的版本 1 <dependencies> 2 <dependency> 3 <groupId>com.oracle.dat ...
- 一款连接SqlServer的数据库工具
由于自己使用的电脑系统是xp,而服务器上的数据库是SqlServer2012,于是用SqlServer2005管理端操作2012,总是不成功.在网上也百度谷歌了很久,也没有解决,也发了很多问没有找到解 ...
- Python学习笔记-Django连接SQLSERVER
Django连接SQLSERVER使用的是odbc驱动. CentOS下安装django-obdc-azure时需安装依懒 yum install gcc yum install gcc-c++ yu ...
- 字符串格式连接sqlserver数据库的字段概念解释
以连接sqlserver数据库举例说明如:“Provider=SQLOLEDB.1;Password=******;Persist Security Info=True;User ID=sa;Init ...
- ORACLE连接SQLSERVER
一.实验(实验成功) 1.实验目标:ORACLE连接SQLSERVER以及查询数据 2.搭建的环境: oracle 9i 9.0.2.0.1 地址:192.168.40.139 sql2000 的数据 ...
随机推荐
- [妙味Ajax]第三课:AJAX跨域解决方案:JSONP
知识点总结: JSONP(JSON with Padding): 1.script标签 2.用script标签加载资源是没有跨域问题的 在资源加载进来之前定义好一个函数,这个函数接收一个参数(数据), ...
- java web应用程序目录
WEB-INF是用来存储服务端配置文件信息和在服务端运行的类文件的,它下面的东西不允许客户端直接访问的.
- MongoDB数据模型(三)
六.数据模型引用 文档 我们已经知道MongoDB以文档的形式存储数据,而文档是JSON风格的数据结构,由一系列的“字段名-值”对组成,如下所示 { "item": "p ...
- SOJ 1210 二叉树
1210. 二叉树 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description 在众多的数据结构中,二叉树是一种特殊而重要的结构,有 ...
- Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
在mac上面安装mysql之后,输入mysql一直报错,可以通过下面的方法解决. mysqld stop mysql.server start http://stackoverflow.com/q ...
- 朋友遇到过的t厂面试题
朋友遇到过的t面试题 leetcode160 找链表交点 leetcode206 反转链表
- LeetCode OJ 45. Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Arch安装fcitx输入法
安装fcitx,安装gtk.qt模块. [root@ARCH ~]# pacman -S fcitx-im :: There are 4 members in group fcitx-im: :: R ...
- $addToSet $push
结果:
- jvm工具的使用
打开Java VisualVm->工具->插件 如图: 关于要填写的URL地址到 http://visualvm.java.net/pluginscenters.html 找到jdk版本 ...