VB.net ConnectionStrings对象参考 [英] VB.net ConnectionStrings object reference

查看:128
本文介绍了VB.net ConnectionStrings对象参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

连接时出现错误:
对象引用未设置为对象实例

Form1

Dim c As String = System.Configuration.ConfigurationManager.ConnectionStrings("CON").ConnectionString
Dim con As New MySqlConnection(c)

App.config

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
      <add name="CON" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=DATABASE_;Uid=user;Pwd=pass" />
    </connectionStrings>
</configuration>

我不知道如何解决此问题...

I have no idea how to fix this issue...

这行得通

Dim con As New MySqlConnection("Server=localhost;Database=DATABASE_;Uid=user;Pwd=pass")

最终,我正在尝试保护我的连接字符串。

Ultimately i am trying to protect my connection string.

调试输出:
在Loader.exe中发生类型为'System.NullReferenceException'的第一次机会异常
这就是说系统。 Configuration.ConfigurationManager.ConnectionStrings( CON)。ConnectionString返回null

Debug output: A first chance exception of type 'System.NullReferenceException' occurred in Loader.exe This is saying that System.Configuration.ConfigurationManager.ConnectionStrings("CON").ConnectionString is returning null

推荐答案

在app.config和码。

You've differents names in app.config and code.

Imports System.Configuration.ConfigurationManager
Dim cs As String = ConnectionStrings("CON").ConnectionString

编辑

问题是错误的app.config安装文件。请阅读评论。

The problem was a bad app.config setup file. Please read the comments.

这篇关于VB.net ConnectionStrings对象参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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