如何通过web.config连接到Access数据库 [英] How to connect to an Access database via web.config
问题描述
谁能告诉我如何使用web.config文件连接数据库.我正在使用Access.我想检查数据库中的用户名和密码.我无法使用VB.NET通过web.config连接到数据库.
Hi,
Can anybody tell me how to connect to a database using the web.config file. I''m using Access. I want to check for username and password in the database. I''m unable to connect to the database through web.config using VB.NET.
//in vb.net
Dim connStr As String = ConfigurationManager.ConnectionStrings("MainConnStr").ConnectionString
sqlcom = New OleDbCommand("select * FROM registered_customers WHERE login_name= '" & userName & "' AND pword='" & password & "'", connstr)
//in web.config
<removed name="LocalSqlServer"" />
<removed name="LocalSqlServer" connectionsting="Data Source=E:\Anil\kank.mdb;User Instance=true" providername="Microsoft.Jet.OLEDB.4.0">
Error: value of type string cannot be converted to system.data.oledb.oledbconnection
如何更改连接字符串以打开连接?
Error: value of type string cannot be converted to system.data.oledb.oledbconnection
How should I change the connectionstring to open the connection?
推荐答案
在页面后面的代码中
//对于C#
OleDbConnection con =新的OleDbConnection(ConfigurationManager.ConnectionStrings [sa1] .ConnectionString);
con.Open();
在web.config
< connectionStrings>
< add name = sa1 connectionString ="Provider = Microsoft.Jet.OLEDB.4.0;数据源= C:\\ a \\ Database1.mdb" providerName ="System.Data.OleDb">
< connectionStrings>
in code behind page
// For C#
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings[sa1].ConnectionString);
con.Open();
in web.config
<connectionStrings>
<add name=sa1 connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\a\\Database1.mdb" providerName="System.Data.OleDb">
<connectionStrings>
这可以帮助您弄清楚: ConnectionStrings.com [ ^ ].
This might help you to figure it out: ConnectionStrings.com[^].
是的,我知道了,连接到数据库:使用Web> config(VB)
只是添加答案,因为它可能会对某人有所帮助
在web.config
yes i got it, Connection To Database: Using Web>config(VB)
just im adding answer as it might help someone
in web.config
<connectionStrings>
<add name="MainConnStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\vana\Anil\kan.mdb;"/>
</connectionStrings>
并在.aspx.vb
中
strconnection =新的OleDbConnection(ConfigurationManager.ConnectionStrings("MainConnStr").ConnectionString)
strconnection.Open()
and in .aspx.vb
strconnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("MainConnStr").ConnectionString)
strconnection.Open()
这篇关于如何通过web.config连接到Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!