YAFLogo

testaja
  • testaja
  • 57.8% (Neutral)
  • YAF Camper Topic Starter
12 years ago
Dear all,

Pls help. the error message as stated below.


Thanks

Note : when i look at SqlServerMajorVersionAsShort method, there is a SERVERPROPERTY('productversion'), i run it on my query analyzer, it returns '8.00.194', so when the program try to parse PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),4)), it returns Null. is that the cause of the problem? how to solve it?




Object cannot be cast from DBNull to other types.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToUInt16(IFormatProvider provider) +56
System.Convert.ToUInt16(Object value) +28
YAF.Classes.Data.DB.SqlServerMajorVersionAsShort() +79
YAF.Classes.Data.DB.system_initialize_executescripts(String script, String scriptFile, Boolean useTransactions) +77
YAF.Install._default.ExecuteScript(String scriptFile, Boolean useTransactions) +240
YAF.Install._default.UpgradeDatabase(Boolean fullText) +74
YAF.Install._default.Wizard_NextButtonClick(Object sender, WizardNavigationEventArgs e) +976
System.Web.UI.WebControls.Wizard.OnNextButtonClick(WizardNavigationEventArgs e) +108
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +418
System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +19
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Thanks
Sponsor

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 3.0.3
12 years ago
I just have the same error on my website while installing yaf 1.94 final.

I made a dirty workaround for that problem

i Replaced line

ushort sqlMajVersion = SqlServerMajorVersionAsShort();

with:

ushort sqlMajVersion;

try
      {
          sqlMajVersion = SqlServerMajorVersionAsShort();
      }
      catch (Exception)
      {
          sqlMajVersion = 8;
      }

But there will be other errors in the procedures.sql.

Sql 2000 isnt a good idea to use with yaf 1.94 anymore.
testaja
  • testaja
  • 57.8% (Neutral)
  • YAF Camper Topic Starter
12 years ago
thanks tha_watcha,
can i use sql server express 2005 to try it ? is it going to work?
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 3.0.3
12 years ago
yes that works.
testaja
  • testaja
  • 57.8% (Neutral)
  • YAF Camper Topic Starter
12 years ago
thanks alot tha_watcha, it works finally!!! now i can play around with the functionality and coding. really appreciate!
bbobb
  • bbobb
  • 100% (Exalted)
  • YAF Developer
12 years ago
Try and run the code by hand:
SELECT convert(tinyint, PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),4))

Was known to work with every ms sql server version >=2000.
It's not quite clear why you have some problems with DbNull value.
testaja
  • testaja
  • 57.8% (Neutral)
  • YAF Camper Topic Starter
12 years ago
bbobb wrote:

Try and run the code by hand:
SELECT convert(tinyint, PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),4))

Was known to work with every ms sql server version >=2000.
It's not quite clear why you have some problems with DbNull value.



Hi bbobb,

here is the detail statement i run on my sql server 2000 :

SELECT SERVERPROPERTY('productversion'), it returns '8.00.194'

hence :
SELECT PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),1), it returns '194'
SELECT PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),2), it returns '00'
SELECT PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),3), it returns '8'
SELECT PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),4), it returns 'null' (8 is the major version)

now on my SQL Server EXPRESS 2005 :
SELECT SERVERPROPERTY('productversion'), it returns '9.00.1399.06'
hence:
SELECT PARSENAME(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')),4), it returns '9' (the major version)


Summary :
=========
on my sql server 2000, product version is : 8.00.194 (it's only three levels)
on my sql server 2005 (Express), product version is : 9.00.1399.06 (it's four levels)


To anticipate, the coding might need to be changed to :
SELECT SUBSTRING(CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')), 1, PATINDEX('%.%', CONVERT(VARCHAR(20), SERVERPROPERTY('productversion')))-1)

afterall, new coding above is only a suggestion, you may have a better way :cheesy: .
YAF Logo Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved
About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button