ConnectionString property error when viewing form in designer

J

jmorgret

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
 
J

Jack Jackson

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?
 
J

jmorgret

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
 
J

Jack Jackson

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
 
A

Armin Zingler

jmorgret said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top