Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • naren 7 posts 27 karma points
    Jul 28, 2011 @ 01:46
    naren
    0

    Cannot connect to the database from a stand alone module on a Umbraco Website

    Hello All,

    I am new to Umbraco. I have trouble in connecting to the MySQL Data from a stand alone application on a Umbraco Website. The application is trying to connect to the same database as the main application. The connection string is in the config file in the format <add key="umbracoDbDSN" value="Datalayer=MySQL; Database=mydb; Server=myserver; User ID=myuser; Password=mypass;" />. I am just trying to open the database on button click and retrive some rows. I can see the application getting the string from the webconfig file but is failing on conn.open(). I am just doing this 

    protected void btnLogin_Click(object sender, EventArgs e)

    {

    MySqlConnection conn = new MySqlConnection(WebConfigurationManager.AppSettings["umbracoAlumniDbDSN"]);

    conn.Open();

    ltrMessage.Text = WebConfigurationManager.AppSettings["umbracoAlumniDbDSN"];

    }

    I get the error An error occurred while processing your request. Is there a way for reading the content on the error message? Any help would be greatly apreciated.

    Thanks

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 28, 2011 @ 08:24
    Dirk De Grave
    0

    naren,

    Should use the ISqlHelper interface to retrieve info from your MySql database if you're in the umbraco context. Code snippet to insert a record in a custom table YourTable:

    var sqlHelper = umbraco.BusinessLogic.Application.SqlHelper;
    sqlHelper.ExecuteNonQuery("INSERT INTO YourTable(Id) VALUES (@id)", sqlHelper.CreateParameter("@id", id));

    Hope this helps.

    Regards,

    /Dirk

  • naren 7 posts 27 karma points
    Jul 28, 2011 @ 19:25
    naren
    0

    Thanks a lot Dirk, you made my day. I was able to connect to the database using ISqlhelper. Dirk can you please direct me on expanding or getting a log on the error messages. Everytime something goes wrong the only error message i see is An error occurred while processing your request. It would help me a lot if i am able to know what the error is in detail. I tried using ?umbdebugshowtrace=true but does not work always. Once again thanks a lot for your help.

    Regards

    Naren

Please Sign in or register to post replies

Write your reply to:

Draft