error message from DatabaseHelper.GetReader() when specifying a different conn string

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/30/2014 1:36:43 PM
Gravatar
Total Posts 11

error message from DatabaseHelper.GetReader() when specifying a different conn string

I am trying to do what is described in the documentation here:

https://www.mojoportal.com/using-a-different-database-for-a-feature.aspx

The message is:

"Format of the initialization string does not conform to specification starting at index 0"

My connection string from user.config is:

<add key="northWindConnectionString" value="Data Source=.\SQLExpress;Database=Northwind;uid=sa;Pwd=AAABBB123" />

My feature code is like this:

try{
IDataReader reader = DatabaseHelper.GetReader("northwindConnectionString", "SELECT * FROM [Products by Category]"))
} catch(Exception exc) {
  TextBox1.Text = "bug="+ exc.Message;
}

Can anyone provide any guidance?

Thanks in advance.

Regards..
-----------------------------------------
BTW I dug down into dbportal.cs and connectionstring.cs, but I could not see where my problem is.

 

 

6/30/2014 1:47:27 PM
Gravatar
Total Posts 18439

Re: error message from DatabaseHelper.GetReader() when specifying a different conn string

The article you linked is about using a different appsetting for a connection string in your custom feature. it has no relation to the DatabaseHelper class.

For DatabaseHelper.GetReader, that first parameter is to override the connection string, if you want to connect to the mojoportal database you just pass in empty string, if you want to connect to another database you must pass in the full connection string not the name of a setting key.

and when using a datareader you must dispose of it so the only safe way is wrap it in a using so it gets disposed automatically

using(IDataReader reader = DatabaseHelper.GetReader("your real connection string", "SELECT * FROM [Products by Category]")))
{
while(reader.Reader())
{

}

}

if you feel to do that it will leave the connection open and exhaust the connection pool

6/30/2014 3:11:24 PM
Gravatar
Total Posts 11

Re: error message from DatabaseHelper.GetReader() when specifying a different conn string

Thank you...your reply got me going in the right direction...

My main issue was that I am pointing at a non-default DB instance...so the back-slash was messing up the string..

Of  course, '@' fixed it and it worked right away!

Regards..

You must sign in to post in the forums. This thread is closed to new posts.