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
<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. 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. Thanks,
Note I have an MS Access Database and Im connecting through odbc
Check out this article...
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
. This method should allow you use your DSN if you specify it in the "server" property:
<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 %>" />
精彩评论