Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error while trying to implement master details table

Tags:

c#

mysql

I trying to implement Master Details table as shown below but I am getting error that says

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

anyone can help me with this issue ?

**and I think their is a better way to do something like that so if yes please give me a link or tell me about what should I search please? **

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoanReports.aspx.cs" Inherits="BankingDemo.LoanReports" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Banking Site (Demo)</title>
    <link href="StyleSheet.css" rel="stylesheet" />
</head>
<body>
    <form id="form" runat="server">
        <asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="CornflowerBlue"  HeaderStyle-Font-Bold="true"  HeaderStyle-ForeColor="White"
             OnPageIndexChanging="GridView1_PageIndexChanging" DataKeyNames="LOAN_NUMBER" DataSourceID="QurClients" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
            AutoGenerateColumns="False" AllowPaging="True" PageSize="10"  AllowCustomPaging="False" AutoGenerateSelectButton="true"
             PagerSettings-Mode="Numeric" CellPadding="5" PagerSettings-PageButtonCount="5" SelectedRowStyle-CssClass="SelectedRow">
            <RowStyle VerticalAlign="Top" />
            <Columns>
                <asp:BoundField DataField="LOAN_NUMBER" HeaderText="LOAN NUMBER" ReadOnly="true" SortExpression="LOAN_NUMBER" />
                <asp:BoundField DataField="FIRST_NAME" HeaderText="First Name" ReadOnly="true" SortExpression="FIRST_NAME"  />
                <asp:BoundField DataField="FATHER_NAME" HeaderText="Father Name" ReadOnly="true" SortExpression="FATHER_NAME"  />
                <asp:BoundField DataField="FAMILY_NAME" HeaderText="Family Name" ReadOnly="true" SortExpression="FAMILY_NAME"  />
                <asp:BoundField DataField="MOTHER_NAME" HeaderText="Mother Name" ReadOnly="true" SortExpression="MOTHER_NAME"  />
                <asp:BoundField DataField="SEX" HeaderText="SEX" ReadOnly="true" SortExpression="SEX" />
                <asp:BoundField DataField="BIRTH_DATE" HeaderText="BIRTH_DATE" ReadOnly="true" SortExpression="BIRTH_DATE" />
                <asp:BoundField DataField="REG_PLACE_TEXT" HeaderText="Register Place" ReadOnly="true" SortExpression="REG_PLACE_TEXT" />
                <asp:BoundField DataField="PHONE" HeaderText="PHONE" ReadOnly="true" SortExpression="PHONE" />
                <asp:CommandField ShowSelectButton="true" SelectText="Details" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" DataKeyNames="LOAN_NUMBER" DataSourceID="QurLoans" Visible="false">
                            <Columns>
                                <asp:BoundField DataField="LOAN_NUMBER" HeaderText="Loan Number" Visible="false" ReadOnly="true" SortExpression="LOAN_NUMBER" />
                                <asp:BoundField DataField="AMOUNT" HeaderText="Amount" Visible="false" ReadOnly="true" SortExpression="AMOUNT" />
                                <asp:BoundField DataField="LOAN_INTEREST" HeaderText="Loan Interset" Visible="false" ReadOnly="true" SortExpression="LOAN_INTEREST" />
                                <asp:BoundField DataField="INTEREST_PERCENT" HeaderText="Interset Percent" Visible="false" ReadOnly="true" SortExpression="INTEREST_PERCENT" />
                                <asp:BoundField DataField="INSTALLMENT_AMOUNT" HeaderText="Instalment Amount" Visible="false" ReadOnly="true" SortExpression="INSTALLMENT_AMOUNT" />
                            </Columns>
                        </asp:GridView>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="QurClients" runat="server" ConnectionString="<%$ ConnectionStrings:ConnConfig %>" SelectCommand="select LOAN_NUMBER,FIRST_NAME,FATHER_NAME,FAMILY_NAME,MOTHER_NAME,SEX,BIRTH_DATE,REG_PLACE_TEXT,address_text,PHONE,profession_text,Notes FROM WORLD.LN_CLIENTS"></asp:SqlDataSource>
        <asp:SqlDataSource ID="QurLoans" runat="server" ConnectionString="<%$ ConnectionStrings:ConnConfig %>" SelectCommand="select LOAN_NUMBER,AMOUNT,LOAN_INTEREST,INTEREST_PERCENT,INSTALLMENT_AMOUNT from ln_loans" >
            <SelectParameters>
                <asp:Parameter Name="LOAN_NUMBER" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <br />
        <div><asp:Button ID="Toxls" runat="server" Text="Export to Excel" OnClick="Toxls_Click" /></div>
    </form>
</body>
</html>

here is the GridView1_SelectedIndexChanged too

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    foreach (GridViewRow row in GridView1.Rows)
    {
        row.FindControl("GridView2").Visible = false;
    }
    QurLoans.SelectParameters[0].DefaultValue = GridView1.SelectedDataKey[0].ToString();
    GridView1.SelectedRow.FindControl("GridView2").Visible = true;
}

the web.config file below

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <connectionStrings>
    <add name="ConnConfig" connectionString="Server=localhost;Database=Mysql;User Id=root;Password=system;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
</configuration>

Stack Trace:

[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +332
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +699
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +89
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +426
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
   System.Data.SqlClient.SqlConnection.Open() +96
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +120
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +136
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1494
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +22
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.GridView.DataBind() +9
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +92
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883
like image 551
sam Avatar asked Mar 19 '26 04:03

sam


1 Answers

Add

ProviderName="<%$ ConnectionStrings:ConnConfig.ProviderName %>"

to your asp:SqlDataSource.

You have to do this because SqlDataSource assumes that you are using a standard SQL server, and since you are trying to connect to MySql, you have to tell it to use the provider name from your connection string.

like image 91
Tamás Szabó Avatar answered Mar 21 '26 18:03

Tamás Szabó



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!