Specified cast is not valid using MVC4 - asp.net-mvc-4

I have the two following web.config file. The first one [1] is running smooth but when I replace it with the second [2] one it's give me and error. I'm using MVC 4.
[1] :
<add name="DBName" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DBName.mdf;Integrated Security=True;User Instance=False"
providerName="System.Data.SqlClient"/>
[2]: When I replace the above with the below I got an error that says "Specified cast is not valid"
<add name="DBName" connectionString="Data Source=ServerName;Initial Catalog=DBName;User ID=Username;Password=Password;Connection Timeout=120"
providerName="System.Data.SqlClient" />

It's impossible to answer definitively with what you've provided, but that particular exception only occurs when a particular table column is of a type that cannot be cast to the type of the property that represents it. If this only happens when you switch between databases, then that means that your schemas of your two database do not match. Ensure that they both have exactly the same schemas, and you'll be fine.

Related

Visual Studio 2015 - Change Setting or Variable at time of Publish

Is it possible to change a setting or variable when the application is published
or is there some sort of condition to run an IF THEN against?
for example, I want to change the way the log files are written when I publish and I often forget to make the change when I publish it
Web.Live.Config:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
-->
<appSettings>
<add key="ClaimPackPath" value="C:\\inetpub\\wwwroot\\Application\\ClaimPacks\\" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>
</configuration>
Wg.Debug.Config:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
-->
<appSettings>
<add key="ClaimPackPath" value="C:\\Debug\\wwwroot\\Application\\ClaimPacks\\" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>
</configuration>
Then in the application you can request the variable like so :
string filepath = ConfigurationManager.AppSettings["ClaimPackPath"];
And it will change for whatever publish profile you choose at time of publish :)

ServiceControl Beta 7.15 RavenDB Error - Failed to execute indexing function on MessagesViewIndex

Helpful information to include
Product name:
Version:
Stacktrace:
Description:
I just upgraded ServiceControl from Beta6 to Beta7.15 and I am getting the following error (see at the bottom of the is post) when I start the service and it just seems to hang there. Note that I deleted the previous database via the following script as outlined in the directions.
net stop "Particular ServiceControl"
RD C:\programdata\particular\ServiceControl\localhost-33333 /S
net start "Particular ServiceControl"
I also configured the ServiceControl config file using the following settings. I used the ServiceControl/Hostname and ServiceControl/ExposeRavenDB setting with Beta 6 with success. I just added ExpirationProcessTimerInSeconds and HoursToKeepMessagesBeforeExpiring using the instructions provided.
<add key="ServiceControl/Hostname" value="*" />
<add key="ServiceControl/ExposeRavenDB" value="true" />
<add key="ExpirationProcessTimerInSeconds" value="600" />
<add key="HoursToKeepMessagesBeforeExpiring" value="168" />
Any assistance you can provide would be greatly appreciated.
2014-03-28 15:49:13.5041|Warn|Raven.Database.Indexing.Index.Indexing|Failed to execute indexing function on MessagesViewIndex on FailedMessages/f027b8ef-2be5-7403-820f-4c358ddecba9
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '!=' cannot be applied to operands of type 'string' and 'int'
at CallSite.Target(Closure , CallSite , Object , Int32 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Index_MessagesViewIndex.<.ctor>b__5e(Object message)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Raven.Database.Indexing.RobustEnumerator.MoveNext(IEnumerator en, StatefulEnumerableWrapper`1 innerEnumerator) in c:\Builds\RavenDB-Unstable-v2.5-New\Raven.Database\Indexing\RobustEnumerator.cs:line 91

What is wrong with my connection string?

I am trying to connect to my shared-hosted database.
They gave me this as an example:
Data Source=KezBlu.db.10971085.hostedresource.com; Initial Catalog=KezBlu; User ID=KezBlu; Password='your password';
From which I made:
<connectionStrings>
<add name="LibKezberProjectManager.Properties.Settings.KezberPMDBConnectionString" connectionString=" Server=****.db.10971085.hostedresource.com; Database=KezBlu; User ID=****; Password=mypassword; Trusted_Connection=False" providerName="System.Data.SqlClient" />
</connectionStrings>
But Linq cannot seem to connect to it.
I am not sure what could be wrong.
It works fine when I use my local SQLExpress...
Thanks
Try using the same keywords as the example given to you by the provider.
So replace Server with Data Source and Database with Initial Catalog.
You may also want to remove Trusted_Connection=False.
For web.config it should be like below:
<add name="KezberPMDBConnectionString" connectionString="Data Source=KezBlu.db.10971085.hostedresource.com;Initial Catalog=KezBlu;User ID=KezBlu;Password=yourpassword" providerName="System.Data.SqlClient"/>
And in to code, access above connection string using following:
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["KezberPMDBConnectionString"].ToString());
Please mark this answer useful if this solve your problem.

tenant-aware datasource in pentaho BI

we have several clients(companies) each of them have separate database i.e companyA has databaseA,CompanyB has databaseB ...etc , so what i want to achieve is, in pentaho user console all of these companies use the same report but with a different datasoruce , for example
CompanyA,CompanyB..etc would have access to a solution-folder called "Reports" this folder has
a list of reports e.g weeklySales_report so i want weeklySales_report to use CompanyA's database when the loged-in user is from companyA and use CompanyB's database when the logged-in user is from companyB,
i tried this but i am getting this error
XmlBeanDefinitionStoreException: Line 67 in XML document from file [C:\pentaho2
biserver-ce\pentaho-solutions\system\pentahoObjects.spring.xml] is invalid; nes
ed exception is org.xml.sax.SAXParseException; lineNumber: 67; columnNumber: 50
The value of attribute "value" associated with an element type "property" must
not contain the '<' character.
it is complaining about <property name="datasourceNameFormat" value="<![CDATA[{0}-{1}]]>
any ideas on what cause this error, or is there any other way to do this
Thanks
I am not sure about your way, but there is simply possibility to have dynamic jndi. You can have jndi in variable in xaction and can use it in xaction for distinguishing target database.
<inputs>
<JNDDDI type="string">
<sources>
<request>JNDDDI</request>
</sources>
<default-value><![CDATA[jndi_database1]]></default-value>
</JNDDDI>
....
<action-definition>
<component-name>SQLLookupRule</component-name>
<action-type>hourly</action-type>
<action-inputs>
<JNDDDI type="string"/>
</action-inputs>
<action-outputs>
<prepared_component type="sql-query"/>
</action-outputs>
<component-definition>
<jndi>{JNDDDI}</jndi>
<query><![CDATA[select ...from ...]]></query>
<live><![CDATA[true]]></live>
</component-definition>
And same thing if you use JasperReport Component.

Replacing sections in web.config using web deployment project

I am trying to replace the following section to blank section ..
<secureWebPages mode="RemoteOnly" encryptedUri="abc.co.uk" unencryptedUri="www.abc.co.uk" maintainPath="True" warningBypassMode="AlwaysBypass" bypassQueryParamName="BypassSecurityWarning" ignoreHandlers="WithStandardExtensions">
<files>
<add path="abc.aspx"/>
</files>
</secureWebPages>
But after executing it is giving me the following error
WDP00002: missing section secureWebPages/configuration.
Can any one plz help me in this regard
This error appears to mean the section you wish to replace, cannot be found in the web.config.
For example, my entry in my WDP read
authentication=authentication.config
However authentication could not be found in the root, as it is under system.web, so I changed it to
system.web/authentication=authentication.config
and this worked.
Note that while debugging this, I tried to replace the whole system.web element, and this did not appear to work either - I am not sure what caused this, but if you cannot replace system.web, I suggest you try a different element, and see if that works, such as connectionStrings
So this problem has popped up for me recently and until finding this I was at a loss.
So it seems that the web.config is made up of not only sections, but section groups as well.
Now system.serviceModel, system.web etc are service groups and as such cannot be replaced as a whole.
You can replace sections in the group by using "section group"/"section"=x.config
Hope this helps :)