G
Graves
Hi
I am trying to learn Vb.net, but have reached a stand still :-(
I am trying to write an updated database connection string to the
application settings.
Try
If Not _IsChanged Then Return
ConnectionFullName =
String.Format("{0}.My.MySettings.DBConnectionString.connectionString.{1}",
System.Reflection.Assembly.GetExecutingAssembly.GetName.Name,
connectionName)
Config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Section = CType(Config.GetSection("connectionStrings"),
ConnectionStringsSection)
Setting = Section.ConnectionStrings(ConnectionFullName)
If IsNothing(Setting) Then Throw New Exception("There is no
connection with this name defined in the config file.")
Setting.ConnectionString = Me._ConnectionString
Config.Save(ConfigurationSaveMode.Full)
My.MySettings.Default.Item(connectionName) = Me._ConnectionString
Catch ex As Exception
Throw New Exception(String.Format("Failed saving connection
'{0}':{1}{2}", connectionName, vbCrLf, ex.Message), ex)
End Try
But still i am getting an error:
System.Exception was unhandled
Message="Failed saving connection 'Data Source=GK-PC02\SQLEXPRESS;Initial
Catalog=db2;Persist Security Info=True;User ID=sa;Password=': There is no
connection with this name defined in the config file."
Can anyone tell me what i do wrong?
Thank on advance
I am trying to learn Vb.net, but have reached a stand still :-(
I am trying to write an updated database connection string to the
application settings.
Try
If Not _IsChanged Then Return
ConnectionFullName =
String.Format("{0}.My.MySettings.DBConnectionString.connectionString.{1}",
System.Reflection.Assembly.GetExecutingAssembly.GetName.Name,
connectionName)
Config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Section = CType(Config.GetSection("connectionStrings"),
ConnectionStringsSection)
Setting = Section.ConnectionStrings(ConnectionFullName)
If IsNothing(Setting) Then Throw New Exception("There is no
connection with this name defined in the config file.")
Setting.ConnectionString = Me._ConnectionString
Config.Save(ConfigurationSaveMode.Full)
My.MySettings.Default.Item(connectionName) = Me._ConnectionString
Catch ex As Exception
Throw New Exception(String.Format("Failed saving connection
'{0}':{1}{2}", connectionName, vbCrLf, ex.Message), ex)
End Try
But still i am getting an error:
System.Exception was unhandled
Message="Failed saving connection 'Data Source=GK-PC02\SQLEXPRESS;Initial
Catalog=db2;Persist Security Info=True;User ID=sa;Password=': There is no
connection with this name defined in the config file."
Can anyone tell me what i do wrong?
Thank on advance