Solved

The ConnectionString property has not been initialized.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get the web content with different encodings 2 44
Install Problem 13 29
Sent email using Shared Mailbox from outlook in C# 5 22
Hey!! 5 33
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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