Solved

The ConnectionString property has not been initialized.

Posted on 2011-03-12
5
716 Views
Last Modified: 2012-05-11
Hi All I am trying to use the SqlDataSource to query a mysql db. I am using the following code


String connectionString = (String)ConfigurationSettings.AppSettings["mysqlConnectionString"];
        string oQRY =
               @"SELECT [ID], [username], [forename], [surname] FROM (select [ID], [username], [forename], [surname], row_number()over(order by t.[surname]) as [rn] from [users] as t where (([forename] + ' ' + [surname]) LIKE @filter)) as st where st.[rn] between @startIndex and @endIndex";

        SqlDataSource ds = new SqlDataSource(connectionString, oQRY);

        ds.SelectParameters.Clear();
        ds.SelectParameters.Add("filter", TypeCode.String, string.Format("%{0}%", e.Filter));
        ds.SelectParameters.Add("startIndex", TypeCode.Int64, (e.BeginIndex + 1).ToString());
        ds.SelectParameters.Add("endIndex", TypeCode.Int64, (e.EndIndex + 1).ToString());
        comboBox.DataSource = ds;
        comboBox.DataBind();

however I am getting the error The ConnectionString proprty has not been initialized. Any ideas why?

Matt
0
Comment
Question by:flynny
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 35118328
Normally means that mysqlConnectionString doesn't exist in web.config.
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35121357
can you show your web.config file?
0
 

Author Comment

by:flynny
ID: 35123252
heres the connection string section from the web.config

      <connectionStrings>
            <add name="mysqlConnectionString" connectionString="Server=xxx;Database=xxx;User=xxx;Password=xxx" providerName="MySql.Data.MySqlClient"/>
      </connectionStrings>
0
 
LVL 9

Accepted Solution

by:
mayank_joshi earned 500 total points
ID: 35126680
You are finding the connection string in AppSettings section while it is located in
ConnectionStrings section.

try:-
String ConnectionString=ConfigurationManager.ConnectionStrings("mysqlConnectionString").ConnectionString;

Open in new window

0
 

Author Closing Comment

by:flynny
ID: 35127338
duh sorry for being dumb.

thanks a bunch!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now