Solved

The ConnectionString property has not been initialized.

Posted on 2011-03-12
5
726 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

829 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