Database Connection Problem
Hey, I don't really understand database connection strings so I'm having problems debugging it. Any help not only figuring out the problem but also what is going on would be really apprecia开发者_运维知识库ted:
I have a website on my localhost and I'm trying to get a sqldatasource to populate my gridview but it gives me the error 'Data source name not found and no default driver specified'.
My page says:
<asp:gridview id="AllOrdersChart" runat="server" Width="100%" DataSourceID="SqlDataSource1">
</asp:gridview>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:lollipopDB %>"
ProviderName = "System.Data.Odbc"
SelectCommand="SELECT * FROM LollipopsDB"></asp:SqlDataSource>
and my web.config says:
<connectionStrings>
<add name="lollipopDB" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\inetpub\wwwroot\Lollipops\App_Data\lollipopsDB.mdb;"
providerName="System.Data.OleDb" />
</connectionStrings>
Ideas on what is wrong?
as you use an sql datasource you have to change your provider name
<asp:AccessDataSource ConnectionString="<%$ ConnectionStrings:lollipopDB %>"
ProviderName = "System.Data.OleDb"
SelectCommand="SELECT * FROM LollipopsDB"> </asp:AccessDataSource>
instead
<asp:SqlDataSource> </asp:SqlDataSource>
Your provider names don't match, for starters. Try using System.Data.OleDb for both.
Have you already created the DSN (data source name) on the system? If not, you'll need to do so under administrative tools in the Windows control panel, before you can access it.
精彩评论