开发者

Object reference not set to an instance of an object. in vb.net

开发者 https://www.devze.com 2023-03-09 13:50 出处:网络
I got this error : \"Object reference not set to an instance of an object.\" in vb.net windows application for sql connection string

I got this error : "Object reference not set to an instance of an object." in vb.net windows application for sql connection string here is the code:

 Dim sqlcon As New SqlConnection(ConfigurationManager.ConnectionStrings("strcon")
                                                     .ConnectionString)

I am getting error for this line

Th开发者_StackOverflow社区anks in advance


It looks as if there is no connection string named strcon in your app.config.


It seems that there is no connection string in your config with name "strcon"... in case strcon is a variable in your code then you need to remove the "" from the strcon as shown below:

Dim sqlcon As New SqlConnection(ConfigurationManager.ConnectionStrings(strcon).ConnectionString)


Check this line of the code

ConfigurationManager.ConnectionStrings("strcon").ConnectionString

its returning value or not / error is coming because this may returning no vlaue i.e null value

one more thing have look to your configuration file and check for the "strcon" name connectionstring i.e it exist or not

also you typed correct spell or not


the connection string: strcon most likely does not exist in your app.config


You would be getting a Null Reference Exception Check if you have defined strcon as connection string in web.config

0

精彩评论

暂无评论...
验证码 换一张
取 消