Problems connecting to SQL

Discussion in 'Databases' started by wisemx, Jan 21, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. You should be able to connect to your Fusion Charts locally from the remote data but...
    If DASP Supports Fusion Charts I'm not aware of it.

    As for your connection string, try this method...Insures naming integrity:
    <connectionStrings>
    <clear/>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="Data Source=tcp:sql2k507.discountasp.net;Initial Catalog=SQL2005_xxxxxx;User ID=SQL2005_xxxxxuser;Password=xxxxx;" providerName="System.Data.SqlClient"/>
    <remove name="sqlServerConnection"/>
    <add name="sqlServerConnection" connectionString="Data Source=tcp:sql2k507.discountasp.net;Initial Catalog=SQL2005_xxxxxx;User ID=SQL2005_xxxxxuser;Password=xxxxx;" providerName="System.Data.SqlClient"/>
    </connectionStrings>
     
  2. Thanks for the swift reply. I have tested Fusion Charts and they do work on DiscountASP. I tried the new connection string you provided but it does not work. I have uploaded my test pages to the server and i will try to connect to the sql database from there. Is the connection string much different to do that?


    tessy
     
  3. Do they really? Cool. Didn't know. [​IMG]

    Yes, that is the same conn string method I use to test locally and remote.
    I've got SQL Server 2005 running locally but to insure my connections I typically string to the remote DASP server.
    Salute,
    Mark
     
  4. I was curious about these Fusion Charts and started ready up on them.
    Very interesting indeed.

    While on their site I found some very significant information about the way the components usedata providers.
    http://www.fusioncharts.com/Docs/Index.html

    Look in the ASP.NET sections under Guide for Web Developers.
     
  5. Thanks Mark

    I have been following the documentation carefully for a few weeks and can create some really cool gadgets and charts. I really need to get the charts to grab info from the databases and have been stuck one one stupid line of code for 3 days! The document on Plotting from a database is straight forward. I really dont know what it is I am doing wrong. Time is running out for me and I can seem to find a solution. I still get the same error. Somewhere in my code there is a mistake. Can you help

    copy of web.config
    connectionStrings>
    <clear/>
    <remove name='LocalSqlServer'/>
    <add name='LocalSqlServer' connectionString='Data Source=tcp:sql2k507.discountasp.net;Initial Catalog=SQL2005_xxxxxx;User ID=SQL2005_xxxxx_phd_user;Password=xxxxxx;'
    providerName='System.Data.SqlClient' />
    <remove name='sqlServerConnection'/>
    <add name='sqlServerConnection' connectionString='Data Source=sql2k507.discountasp.net;Initial Catalog=SQL2005_xxxxx_phd;User ID=SQL2005_xxxxx_phd_user;Password=xxxxx'
    providerName='System.Data.SqlClient' />
    <!--<add name='MSAccessConnection' connectionString='Data Source=/_database/FactoryDB.mdb' providerName='Microsoft.Jet.OLEDB.4.0' />-->
    </connectionStrings>


    copy of DBConn.cs
    using System;
    using System.Data;
    using System.Data.Odbc;
    using System.Web;
    using System.Configuration;

    namespace DataConnection
    {
    /// <summary>
    /// DataBase Connection Class.
    /// </summary>
    public class DbConn
    {

    // Create a database Connection. using here Access Database
    // Return type object of OdbcConnection

    public OdbcConnection connection;
    public OdbcDataReader ReadData;
    public OdbcCommand aCommand;
    /// <summary>
    /// Data Connection and get Data Reader
    /// </summary>
    /// <param name='strQuery'>SQL Query</param>
    public DbConn(string strQuery)
    {
    // MS Access DataBase Connection - Defined in Web.Config
    string connectionName = 'MSAccessConnection';

    // SQL Server DataBase Connection - Defined in Web.Config
    //string connectionName = 'sqlServerConnection';



    // Creating Connection string using web.config connection string
    string ConnectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;
    try
    {
    // create connection object
    connection = new OdbcConnection();
    // set connection string
    connection.ConnectionString = ConnectionString;
    // open connection
    connection.Open();
    // get reader
    GetReader(strQuery);
    }
    catch (Exception e)
    {
    HttpContext.Current.Response.Write(e.Message.ToString());
    }

    }

    // Create an instance dataReader
    // Return type object of OdbcDataReader
    /// <summary>
    /// Get Data Reader
    /// </summary>
    /// <param name='strQuery'>SQL Query</param>
    public void GetReader(string strQuery)
    {
    // Create a Command object
    aCommand = new OdbcCommand(strQuery, connection);

    // Create data reader object using strQuery string
    // Auto close connection
    ReadData = aCommand.ExecuteReader(CommandBehavior.CloseConnection);

    }

    }
    }

    Copy of DBExample

    sing System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;
    using InfoSoftGlobal;
    using DataConnection;

    public partial class DBExample_BasicDBExample : System.Web.UI.Page
    {

    public string GetFactorySummaryChartHtml()
    {
    //In this example, we show how to connect FusionCharts to a database.
    //For the sake of ease, we've used an Access database which is present in
    //../App_Data/FactoryDB.mdb. It just contains two tables, which are linked to each
    //other.

    //xmlData will be used to store the entire XML document generated
    StringBuilder xmlData=new StringBuilder();

    //Generate the chart element
    xmlData.Append('<chart caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' formatNumberScale='0' numberSuffix=' Units'>');

    //Create recordset to get details for the factories
    //string factoryQuery = 'select a.studentID,a.firstname from students a';
    string factoryQuery = 'select a.FactoryId,a.FactoryName,sum(b.Quantity) as TotQ from Factory_Master a,Factory_Output b where a.FactoryId=b.FactoryID group by a.FactoryId,a.FactoryName';
    DbConn oRs = new DbConn(factoryQuery);

    //Iterate through each record
    while (oRs.ReadData.Read()){
    //Generate <set name='..' value='..' />
    xmlData.AppendFormat('<set label='{0}' value='{1}' />',oRs.ReadData['FactoryName'].ToString(), oRs.ReadData['TotQ'].ToString() );
    }

    oRs.ReadData.Close();
    //Close chart element
    xmlData.Append('</chart>');

    //Create the chart - Pie 3D Chart with data from xmlData
    return FusionCharts.RenderChart('../FusionCharts/Pie3D.swf', '', xmlData.ToString(), 'FactorySum', '600', '300', false, false);
    }
    }
     
  6. in the above code i realise the MSAccess connection is still active - I had given up on the SQL earlier and was trying it out.
     
  7. Switching to Access until you get it working it probably a good idea.
    One thing that stands out is the ODBC connection to a .NET Access DB.
    You should be using OleDB.
    http://www.connectionstrings.com/?carrier=access

    An example I use here right now is:

    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.OleDb" %>
    Dim strConnection As String = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + Server.MapPath("../_database/database.mdb")
     
  8. Hi, I am new to ASP.NET and c# and i have to create a website with charts etc for my PhD research. I have been able to connect to an SQL database using the built in sqlDataSource. I have also been able to display Fusion Charts. However, I now need to connect the charts to the database and this requires to manually configure the connectionString. I was able to connect to my local server but not to my webspace db. I have been following the database example (which uses an access db) given by fusion charts found at http://www.fusioncharts.com/Docs/Index.html - (Using ASP.NET and C#, Plotting from a database) which gives the following line commented out for SQL

    <!--<add name='sqlServerConnection' connectionString='Driver={SQL Server};;uid=sa;pwd=;server=Infosoft;database=FactoryDB'/>-->

    I changed this to:

    <add name='sqlServerConnection' connectionString='Data Source=tcp:sql2k507.discountasp.net;Initial Catalog=SQL2005_xxxxxx;User Id=SQL2005_xxxxxuser;Password=xxxxx'/>

    Unfortunately I cant get it to work!

    I am also posting this on Fusion Charts forum to see if anyone can help there.


    thanks

    tessy
     
  9. Hi Mark

    I made some changes using your suggestions and I am delighted to say that the problem is now resolved! I can now view a very nice Pie Chart that is grabbing data from my SQL database.

    Thanks for all your help, it is much appreciated.

    tessy
     
  10. I very much appreciate the update, and the kinds words.
    All the best,
    Mark
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page