[英]How do I connect to an Access Database through an ODBC DSN using an ASP.Net Data Source?
I have a dsn connection to the database and I have the following command in asp.net to connect to it我有一个到数据库的 dsn 连接,我在 asp.net 中有以下命令来连接它
<asp:AccessDataSource ID="SqlDataSource1" runat="server" DSN="tuition" SelectCommand="Select * From [table1]"></asp:AccessDataSource>
However the problem is that when using AccessDataSouce we can't use DSN.然而问题是当使用 AccessDataSouce 时我们不能使用 DSN。 Is their any other way to get around that( or probably use something else ).
他们是否有任何其他方式来解决这个问题(或者可能使用其他东西)。 As long as Im using DSN Im fine, any help would be greatly appreciated.
只要我使用 DSN 我很好,任何帮助都将不胜感激。 Thanks,
谢谢,
Note I have an MS Access Database and Im connecting through odbc注意我有一个 MS Access 数据库,我通过 odbc 连接
Check out this article...看看这篇文章...
http://msdn.microsoft.com/en-us/library/35c54x95(v=vs.80).aspx http://msdn.microsoft.com/en-us/library/35c54x95(v=vs.80).aspx
it explains how to connect to an ODBC database using a SqlDataSource
instead of an AccessDataSource
.它解释了如何使用
SqlDataSource
而不是AccessDataSource
连接到 ODBC 数据库。 This method should allow you use your DSN if you specify it in the "server" property:如果您在“服务器”属性中指定,此方法应该允许您使用您的 DSN:
<configuration>
<connectionStrings>
<add
name="ODBCDataConnectionString"
connectionString="Driver=ODBCDriver;server=tuition;"
providerName="System.Data.Odbc"
/>
</connectionStrings>
</configuration>
Then change your data source to:然后将您的数据源更改为:
<asp:SqlDataSource
ID="SqlDataSource1"
Runat="server"
SelectCommand="Select * From [table1]"
ConnectionString="<%$ ConnectionStrings:ODBCDataConnectionString %>"
ProviderName="<%$ ConnectionStrings:ODBCDataConnectionString.ProviderName %>" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.