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
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.
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));
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.
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
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:
Hope this helps.
Regards,
/Dirk
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
is working on a reply...