vb.net - Public connection string inaccessible -
i have imported own database connection file doesn't dbconnectdbostr string
any ideas?
imports pirelli.dbpirelli partial class _default inherits system.web.ui.page sub page_load(byval sender object, byval e eventargs) handles mybase.load dim strcmd string dim dbcmd sqlcommand dim oconn sqlconnection dim dbreader sqldatareader oconn = new sqlconnection(dbconnectdbostr) connection file:
imports system.data.sqlclient namespace pirelli public class dbpirelli 'database server - enable 1 public const strservername string = "[server]" 'dev public const dbconnectdbostr string = "uid=[user];password=[pass];database=[db];server=" & strservername & ";connection timeout=60;" end class end namespace i getting error:
description: error occurred during compilation of resource required service request. please review following specific error details , modify source code appropriately. compiler error message: bc30451: name 'dbconnectdbostr' not declared. source error: line 21: line 22: line 23: oconn = new sqlconnection(dbconnectdbostr) line 24: line 25: oconn.open()
since you're not dealing instance of dbpirelli class, should make classs static , call namespace using:
namespace pirelli ' in vb static class called "module" public module dbpirelli 'database server - enable 1 public const strservername string = "[server]" 'dev public const dbconnectdbostr string = "uid=[user];password=[pass];database=[db];server=" & strservername & ";connection timeout=60;" end module end namespace ....
' since you're importing namespace pirelli.dbpirelli, don't need ' call namespace had indicated oconn = new sqlconnection(dbconnectdbostr)
Comments
Post a Comment