App.config连接字符串 [英] App.config Connectionstring

查看:59
本文介绍了App.config连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在使用带有ms访问权限的vb.net Win窗体2005.我想将连接字符串设置为全局.
为此,我将连接字符串放在app.config中,例如:

Hie!

I am using vb.net Win forms 2005 with ms access. I want to make my connectionstring global.
For that i am putting my connectionstring in app.config like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
  </configSections>
  <appSettings >
    <add key ="Test" value ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Transport.mdb" />
  </appSettings>


在我的表格中,我的阅读方式如下:


In my form i read it like:

dim str as string
dim stringcn as string
strincn=configuratiomanager.appsetting("Test")
dim cn as oledbconnection
cn=new oledbconnection(stringcn)
cn.open()
str = "isert into tablename(column1) values(fieldname)"


但是当我运行它时,它不会给出任何错误,但是没有任何内容存储在数据库中.

那是什么问题呢?错误在哪里?
请告诉我.


but when i run it does not give any error but nothing gets stored in the database.

So what is the problem? Where is the mistake?
Please tell me.

推荐答案



您是否已检查过是否可以打开连接?请检查连接对象的状态"属性,以确保确实未创建连接.

Hi,

Have you checked wherther you have been able to Open the connection? Please check the "State" property of connection object to make sure indeed connection is not created.

<br />
cn=new oledbconnection(stringcn);<br />
cn.open()<br />
if(cn.State==ConectionState.Open)<br />
{<br />
   MessageBox.Show("Connection Opened");<br />
}<br />
else<br />
{<br />
   MessageBox.Show("Connection Closed");<br />
}<br />
<br />



如果您看到连接已打开,则问题可能出在其他地方.然后使用try-catch块来确定是否出了问题.



If you see connection is opened, then the problem might be in some other place. Then use try-catch block to identify if anything goes wrong.


尝试一下,尝试下一页

尝试一下


现在已经建立连接,您必须将行插入数据库中
Give this a try a third down the page

Try this


you''ve made the connection now you have to insert the row into the database


这篇关于App.config连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆