PC Review


Reply
Thread Tools Rate Thread

ConnectionString property error when viewing form in designer

 
 
jmorgret
Guest
Posts: n/a
 
      4th May 2009
Whenever I try to view a particular form in Design mode I get the
following error:

The ConnectionString property has not been initialized.

I have seen other posts in regard to this error in ASP.net projects and
in reference to settings in the config files but this is not my
situation. I am in a VB.net project trying to view a windows form.
This is a complex form that has a ton of user controls on it. However
none of the controls have any datacontrols like datagridview or
bindingsource. All our data handling is done through code in our data
layer project so I don't know why this would be an issue at design time.
The project runs fine it just won't let me look at the form.

I searched my code for ConnectionString and I can't find anything and
even though the rest of the error does reference other classes in my
data project, I don't really know what to change because it isn't
pointing to any lines with error just lines like DataAdapter.Fill.
Again the only error is during design not when I run the project. Any
suggestions?

Thanks.
Jennifer



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Jack Jackson
Guest
Posts: n/a
 
      4th May 2009
On Mon, 04 May 2009 15:11:38 -0700, jmorgret <(E-Mail Removed)>
wrote:

>Whenever I try to view a particular form in Design mode I get the
>following error:
>
>The ConnectionString property has not been initialized.
>
>I have seen other posts in regard to this error in ASP.net projects and
>in reference to settings in the config files but this is not my
>situation. I am in a VB.net project trying to view a windows form.
>This is a complex form that has a ton of user controls on it. However
>none of the controls have any datacontrols like datagridview or
>bindingsource. All our data handling is done through code in our data
>layer project so I don't know why this would be an issue at design time.
>The project runs fine it just won't let me look at the form.
>
>I searched my code for ConnectionString and I can't find anything and
>even though the rest of the error does reference other classes in my
>data project, I don't really know what to change because it isn't
>pointing to any lines with error just lines like DataAdapter.Fill.
>Again the only error is during design not when I run the project. Any
>suggestions?
>
>Thanks.
>Jennifer


All of the code in an object runs in the IDE, except for user input
events (mouse and keyboard events). I suspect you have code, perhaps
called from the form's Load event or an event in some control, that is
trying to connect to the database and failing.

Where do you see the error?
 
Reply With Quote
 
jmorgret
Guest
Posts: n/a
 
      5th May 2009
Well, that's just it. I don't see any errors in the code and it
compiles with no errors. So how do I figure out what the problem is? I
go to the lines of code that are referenced in the error I get when
trying to view the form, but there are no errors there.

Here is the entire error message:

The ConnectionString property has not been initialized.
Hide

at System.Data.SqlClient.SqlConnection.PermissionDemand()
at
System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection
outerConnection)
at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at SPSGData.SPSGDataAdaptor.Fill(SqlDataAdapter thisDataAdaptor, DataSet
thisDataSet) in
C:\ST\Projects\ASATDB\Source\SPSGData\Classes\SPSGDataAdaptor.vb:line
650
at SPSGData.SPSGDataAdaptor.Fill(ReminderSet thisDataSet, String filter)
in C:\ST\Projects\ASATDB\Source\SPSGData\Classes\SPSGDataAdaptor.vb:line
633
at SPSGData.ReminderSet..ctor(String filter) in
C:\ST\Projects\ASATDB\Source\SPSGData\Classes\Reminder\ReminderSet.vb:li
ne 59
at SPSGData.DataTransporter.GetReminderSet(String filter) in
C:\ST\Projects\ASATDB\Source\SPSGData\Classes\DataTransporter.vb:line
149
at SPSGBusiness.DataFactory.GetReminderSet(ReminderFilter filter) in
C:\ST\Projects\ASATDB\Source\SPSGBusiness\Classes\DataFactory.vb:line
147
at SPSGBusiness.ReminderCollection..ctor(ReminderFilter filter, Boolean
headerInformationOnly) in
C:\ST\Projects\ASATDB\Source\SPSGBusiness\Classes\Reminder\ReminderColle
ction.vb:line 95
at SPSGBusiness.ReminderCollection.GetAllReminders(Boolean
headerInformationOnly) in
C:\ST\Projects\ASATDB\Source\SPSGBusiness\Classes\Reminder\ReminderColle
ction.vb:line 14
at ASATDB.ReminderControl.ReminderControl_Load(Object sender, EventArgs
e) in C:\ST\Projects\ASATDB\Source\ASATDB\User Controls\Main
Form\ReminderControl.vb:line 31
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
at System.Windows.Forms.UserControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at System.Windows.Forms.Form.ControlCollection.Add(Control value)
at
System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Ad
d(Control c)

But I don't see anything when I go to those lines.

-Jennifer


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Jack Jackson
Guest
Posts: n/a
 
      6th May 2009
On Tue, 05 May 2009 15:05:43 -0700, jmorgret <(E-Mail Removed)>
wrote:

>Well, that's just it. I don't see any errors in the code and it
>compiles with no errors. So how do I figure out what the problem is? I
>go to the lines of code that are referenced in the error I get when
>trying to view the form, but there are no errors there.
>
>Here is the entire error message:
>
>The ConnectionString property has not been initialized.
>Hide
>
>at System.Data.SqlClient.SqlConnection.PermissionDemand()
>at
>System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection
>outerConnection)
>at
>System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
>outerConnection, DbConnectionFactory connectionFactory)
>at System.Data.SqlClient.SqlConnection.Open()
>at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
>ConnectionState& originalState)
>at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
>DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
>srcTable, IDbCommand command, CommandBehavior behavior)
>at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
>startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
>CommandBehavior behavior)
>at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
>at SPSGData.SPSGDataAdaptor.Fill(SqlDataAdapter thisDataAdaptor, DataSet
>thisDataSet) in
>C:\ST\Projects\ASATDB\Source\SPSGData\Classes\SPSGDataAdaptor.vb:line
>650
>at SPSGData.SPSGDataAdaptor.Fill(ReminderSet thisDataSet, String filter)
>in C:\ST\Projects\ASATDB\Source\SPSGData\Classes\SPSGDataAdaptor.vb:line
>633
>at SPSGData.ReminderSet..ctor(String filter) in
>C:\ST\Projects\ASATDB\Source\SPSGData\Classes\Reminder\ReminderSet.vb:li
>ne 59
>at SPSGData.DataTransporter.GetReminderSet(String filter) in
>C:\ST\Projects\ASATDB\Source\SPSGData\Classes\DataTransporter.vb:line
>149
>at SPSGBusiness.DataFactory.GetReminderSet(ReminderFilter filter) in
>C:\ST\Projects\ASATDB\Source\SPSGBusiness\Classes\DataFactory.vb:line
>147
>at SPSGBusiness.ReminderCollection..ctor(ReminderFilter filter, Boolean
>headerInformationOnly) in
>C:\ST\Projects\ASATDB\Source\SPSGBusiness\Classes\Reminder\ReminderColle
>ction.vb:line 95
>at SPSGBusiness.ReminderCollection.GetAllReminders(Boolean
>headerInformationOnly) in
>C:\ST\Projects\ASATDB\Source\SPSGBusiness\Classes\Reminder\ReminderColle
>ction.vb:line 14
>at ASATDB.ReminderControl.ReminderControl_Load(Object sender, EventArgs
>e) in C:\ST\Projects\ASATDB\Source\ASATDB\User Controls\Main
>Form\ReminderControl.vb:line 31
>at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
>at System.Windows.Forms.UserControl.OnCreateControl()
>at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
>at System.Windows.Forms.Control.CreateControl()
>at System.Windows.Forms.Control.ControlCollection.Add(Control value)
>at System.Windows.Forms.Form.ControlCollection.Add(Control value)
>at
>System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Ad
>d(Control c)
>
>But I don't see anything when I go to those lines.
>
>-Jennifer


That pretty much tells you what is wrong.

In the Load event of a UserControl
(C:\ST\Projects\ASATDB\Source\ASATDB\User Controls\Main
Form\ReminderControl.vb:line 31) you start down a path of calling
methods, eventually ending up trying to fill a dataset, and the
connection information is not set up.

You should not be trying to access your database when executing in the
IDE.

The way I detect if I am running in the IDE is with this code. Since
the GetCurrentProcess call is relatively expensive, I have this method
in my application object, and it caches the result.

Public Shared ReadOnly Property IsDesignMode() As Boolean
Get
If Not m_isDesignModeValid Then
' The following test may fail in some situations,
such as when running under Citrix
' due to insufficient privilege. We assume that
if it fails we are not in design mode.
Try
Dim processName As String =
System.Diagnostics.Process.GetCurrentProcess().ProcessName
If processName = "devenv" OrElse
processName.EndsWith("TestContainer") Then
m_isDesignMode = True
End If
Catch ex As Exception

End Try
m_isDesignModeValid = True
End If
Return m_isDesignMode
End Get
End Property
 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      6th May 2009
jmorgret wrote:
> Well, that's just it. I don't see any errors in the code and it
> compiles with no errors. So how do I figure out what the problem is?
> I go to the lines of code that are referenced in the error I get when
> trying to view the form, but there are no errors there.



Whenever you create the Form in your code at runtime, you probably
initialize <whatever> before. This initialization has not been done if an
instance of the Usercontrol is created in the designer. Well, in the end,
"<whatever>" is probably the ConnectionString. From here it's impossible to
say what's missing, so the question is: Are there any preconditions that
must be met to make an instance of your Usercontrol work? To find it out,
add the following code to the start of you Sub Main:

dim f as new form
f.controls.add(new YourUsercontrol)
application.run(f)
return

Does this still work at runtime?

In the simplest case, you have an overloaded constructor receiving the
required data to make the control work. Of course, the designer does not
make use of this constructore.



Armin

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Viewing a form in Designer forces SourceSafe checkout Coderer Microsoft Dot NET Framework Forms 0 22nd Oct 2008 03:38 PM
Dynamic Property Array in Form Designer screamingtarget@gmail.com Microsoft C# .NET 1 16th Jun 2006 10:13 PM
Array of forms as form designer property? =?Utf-8?B?V1hT?= Microsoft Dot NET Framework Forms 0 25th Feb 2005 02:29 PM
ASP.net: Error "Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized." Tony Microsoft ASP .NET 6 15th Jun 2004 10:27 AM
Setting a Property by Default in designer to container form =?Utf-8?B?VHJldm9y?= Microsoft Dot NET Framework 1 13th Mar 2004 12:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:47 AM.