Testing a dagster pipeline - dagster

Summary: Dagster run configurations for Dagit vs. PyTest appear to be incompatible for my project
I've been getting errors trying to run pytest on a pipeline and I'd really appreciate any pointers. I've consistently gotten errors of the form:
dagster.core.errors.DagsterInvalidConfigError:
Error in config for pipeline ephemeral_write_myfunc_to_redis_solid_pipeline
Error 1: Undefined field "myfunc_df_to_list" at path root:solids.
Expected: "{ myfunc_list?: { outputs?: [{ result?: { json: { path: String } pickle: { path: String } } }] }
write_myfunc_to_redis?:..."
A few notes about the project:
dagster, version 0.9.15
my pipeline runs in Dagit without errors for the same configuration
the unit tests run for the individual solids that comprise the pipeline
Failed solutions: I've tried populating the configuration files with solids that define the outputs as each pytest error has recommended, but they all have led to errors more opaque than the one before it.
My solids are:
#solid(required_resource_keys={"db"})
def get_myfunc_df(context, query: String) -> myfuncDF:
do something
return myfuncDF
#solid
def myfunc_df_to_list(context, df: myfuncDF) -> List:
do something
return List
#solid(required_resource_keys={"redis"})
def write_myfunc_to_redis(context, myfunc_list:List) -> None:
write to redis return None
And my pipeline is a chain of these solids
#pipeline(
mode_defs=filter_modes(MODES),
preset_defs=filter_presets(PRESETS),
tags={"type": "myproject"},
)
def myfunc_to_redis_pipeline():
df = get_myfunc_df()
myfunc_list = myfunc_df_to_list(df)
write_myfunc_to_redis(myfunc_list)
My test code in test_main.py is
#pytest.mark.myfunc
def test_myfunc_to_redis_pipeline(self):
res = execute_pipeline(myfunc_to_redis_pipeline,
preset="test",)
assert res.success
assert len(res.solid_result_list) == 4
for solid_res in res.solid_result_list:
assert solid_res.success
Where the preset "test" is defined with the run configuration in a yaml file:
resources:
db:
config:
file_path: test.csv
^ This is where it's throwing the most errors and I've been iterating through different permutations of solids to add ala:
solids:
get_myfunc_df:
inputs:
query:
value: select 1
but it hasn't solved the problem yet. Is there any reason the Solids for a test would need their output defined despite the fact that while running in Dagit, only the input solid needs to have a definition?
Is this error indicative of something else being amiss?
edit: Here is the stack trace from tox --verbose
self = <repos.myfunc.myfunc.dagster.tests.test_main.Test_myfunc testMethod=test_myfunc_df>
#pytest.mark.myfunc
def test_myfunc_df(self):
"""myfunc"""
result = execute_solid(
get_myfunc_df,
mode_def=test_mode,
run_config=run_config,
> input_values={"query": "SELECT 1"},
)
repos/myfunc/myfunc/dagster/tests/test_main.py:29:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/utils/test/__init__.py:324: in execute_solid
raise_on_error=raise_on_error,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/execution/api.py:335: in execute_pipeline
raise_on_error=raise_on_error,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/telemetry.py:90: in wrap
result = f(*args, **kwargs)
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/execution/api.py:375: in _logged_execute_pipeline
tags=tags,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/instance/__init__.py:586: in create_run_for_pipeline
pipeline_def, run_config=run_config, mode=mode,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/execution/api.py:644: in create_execution_plan
environment_config = EnvironmentConfig.build(pipeline_def, run_config, mode=mode)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pipeline_def = <dagster.core.definitions.pipeline.PipelineDefinition object at 0x1359f6210>
run_config = {'resources': {'ge_data_context': {'config': {'ge_root_dir': '/Users/this_user/Workspace/drizly-dagster/repos/datas...cause_you_bought/dagster/tests/test.csv'}}}, 'solids': {'get_myfunc_df': {'inputs': {'query': {'value': 'select 1'}}}}}
mode = 'test'
#staticmethod
def build(pipeline_def, run_config=None, mode=None):
"""This method validates a given run config against the pipeline config schema. If
successful, we instantiate an EnvironmentConfig object.
In case the run_config is invalid, this method raises a DagsterInvalidConfigError
"""
from dagster.config.validate import process_config
from dagster.core.definitions.executor import ExecutorDefinition
from dagster.core.definitions.intermediate_storage import IntermediateStorageDefinition
from dagster.core.definitions.system_storage import SystemStorageDefinition
from .composite_descent import composite_descent
check.inst_param(pipeline_def, "pipeline_def", PipelineDefinition)
run_config = check.opt_dict_param(run_config, "run_config")
check.opt_str_param(mode, "mode")
mode = mode or pipeline_def.get_default_mode_name()
environment_type = create_environment_type(pipeline_def, mode)
config_evr = process_config(environment_type, run_config)
if not config_evr.success:
raise DagsterInvalidConfigError(
"Error in config for pipeline {}".format(pipeline_def.name),
config_evr.errors,
> run_config,
)
E dagster.core.errors.DagsterInvalidConfigError: Error in config for pipeline ephemeral_get_myfunc_df_solid_pipeline
E Error 1: Undefined field "inputs" at path root:solids:get_myfunc_df. Expected: "{ outputs?: [{ result?: { csv: { path: (String | { env: String }) sep?: (String | { env: String }) } parquet: { path: (String | { env: String }) } pickle: { path: (String | { env: String }) } table: { path: (String | { env: String }) } } }] }".
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/system_config/objects.py:101: DagsterInvalidConfigError
_______________________________________________________________________ Test_myfunc.test_write_myfunc_to_redis ________________________________________________________________________
self = <repos.myfunc.myfunc.dagster.tests.test_main.Test_myfunc testMethod=test_write_myfunc_to_redis>
#pytest.mark.myfunc
def test_write_myfunc_to_redis(self):
"""Test redis write"""
records = [
("k", "v"),
("k2", "v2"),
]
result = execute_solid(
write_myfunc_to_redis,
mode_def=test_mode,
input_values={"myfunc_list": records},
> run_config=run_config,
)
repos/myfunc/myfunc/dagster/tests/test_main.py:56:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/utils/test/__init__.py:324: in execute_solid
raise_on_error=raise_on_error,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/execution/api.py:335: in execute_pipeline
raise_on_error=raise_on_error,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/telemetry.py:90: in wrap
result = f(*args, **kwargs)
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/execution/api.py:375: in _logged_execute_pipeline
tags=tags,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/instance/__init__.py:586: in create_run_for_pipeline
pipeline_def, run_config=run_config, mode=mode,
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/execution/api.py:644: in create_execution_plan
environment_config = EnvironmentConfig.build(pipeline_def, run_config, mode=mode)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pipeline_def = <dagster.core.definitions.pipeline.PipelineDefinition object at 0x135d39490>
run_config = {'resources': {'ge_data_context': {'config': {'ge_root_dir': '/Users/this_user/Workspace/drizly-dagster/repos/datas...cause_you_bought/dagster/tests/test.csv'}}}, 'solids': {'get_myfunc_df': {'inputs': {'query': {'value': 'select 1'}}}}}
mode = 'test'
#staticmethod
def build(pipeline_def, run_config=None, mode=None):
"""This method validates a given run config against the pipeline config schema. If
successful, we instantiate an EnvironmentConfig object.
In case the run_config is invalid, this method raises a DagsterInvalidConfigError
"""
from dagster.config.validate import process_config
from dagster.core.definitions.executor import ExecutorDefinition
from dagster.core.definitions.intermediate_storage import IntermediateStorageDefinition
from dagster.core.definitions.system_storage import SystemStorageDefinition
from .composite_descent import composite_descent
check.inst_param(pipeline_def, "pipeline_def", PipelineDefinition)
run_config = check.opt_dict_param(run_config, "run_config")
check.opt_str_param(mode, "mode")
mode = mode or pipeline_def.get_default_mode_name()
environment_type = create_environment_type(pipeline_def, mode)
config_evr = process_config(environment_type, run_config)
if not config_evr.success:
raise DagsterInvalidConfigError(
"Error in config for pipeline {}".format(pipeline_def.name),
config_evr.errors,
> run_config,
)
E dagster.core.errors.DagsterInvalidConfigError: Error in config for pipeline ephemeral_write_myfunc_to_redis_solid_pipeline
E Error 1: Undefined field "get_myfunc_df" at path root:solids. Expected: "{ myfunc_list?: { outputs?: [{ result?: { json: { path: String } pickle: { path: String } } }] } write_myfunc_to_redis?: { outputs?: [{ result?: { json: { path: String } pickle: { path: String } } }] } }".
.tox/repo-myfunc/lib/python3.7/site-packages/dagster/core/system_config/objects.py:101: DagsterInvalidConfigError
=============================================================================== short test summary info ===============================================================================
FAILED repos/myfunc/myfunc/dagster/tests/test_main.py::Test_myfunc::test_myfunc_df - dagster.core.errors.DagsterInvalidConfigError: Error in config for pipeli...
FAILED repos/myfunc/myfunc/dagster/tests/test_main.py::Test_myfunc::test_write_myfunc_to_redis - dagster.core.errors.DagsterInvalidConfigError: Error in conf
Solution below works
The key issue was that the pipeline required solids to be defined in the config as written and the solids were being passed both that same config and input_values in their test function. My change was to remove "input_values" as an argument and pass them via the run configuration. Since my interstitial solids require more complex objects and my configuration file is yaml, I made the following addition to all of my solid tests:
this_solid_run_config = copy.deepcopy(run_config)
input_dict = {"df": pd.DataFrame(['1', '2'], columns = ['key', 'value'])}
this_solid_run_config.update({"solids":
{"myfunc_df_to_list":
{"inputs":input_dict
}
}
}
)

Based on the stack trace, the failure is coming from this:
result = execute_solid(
get_myfunc_df,
mode_def=test_mode,
run_config=run_config,
input_values={"query": "SELECT 1"},
)
The solid input "query" should be passed from either "input_values" param or "run_config" param but not both. Happy to keep digging if that doesn't resolve your issue.

Related

How to Insert Text Watermark in Word with VB.NET

I need to insert text diagonal Watermark, in a word file with OpenXML, I use the following steps to open the file:
Dim wordmlNamespace As String = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
Using wdDoc As WordprocessingDocument = WordprocessingDocument.Open(newPath, True)
'AddWatermarkFunction()
wdDoc.MainDocumentPart.Document.Save()
wdDoc.Close()
End Using
I have already seen this link, but I can not play the correct functioning.
UPDATE
I tried to write the following code (replaces 'AddWatermarkFunction() of the above code), but I do not print the watermark
If wdDoc.MainDocumentPart.HeaderParts IsNot Nothing Then
If wdDoc.MainDocumentPart.HeaderParts IsNot Nothing Then
For Each Headerpart In wdDoc.MainDocumentPart.HeaderParts
Dim r As DocumentFormat.OpenXml.Wordprocessing.Run = CreateWatermarkRun("watermarkText")
Dim para As New DocumentFormat.OpenXml.Wordprocessing.Paragraph
para.Append(r)
Headerpart.Header.Save(Headerpart)
Next
End If
End If
the function "CreateWatermarkRun":
Private Function CreateWatermarkRun(ByVal name As String) As DocumentFormat.OpenXml.Wordprocessing.Run
Dim runWatermark As New DocumentFormat.OpenXml.Wordprocessing.Run()
Dim runWMProperties As New DocumentFormat.OpenXml.Wordprocessing.RunProperties()
Dim noProofWM As New DocumentFormat.OpenXml.Wordprocessing.NoProof()
Try
runWMProperties.Append(noProofWM)
Dim pictureWM As New DocumentFormat.OpenXml.Wordprocessing.Picture()
Dim shapetypeWM As New DocumentFormat.OpenXml.Vml.Shapetype() With
{ _
.Id = "_x0000_t136", _
.CoordinateSize = "21600,21600", _
.OptionalNumber = 136, _
.Adjustment = "10800", _
.EdgePath = "m#7,l#8,m#5,21600l#6,21600e" _
}
Dim formulasWM As New DocumentFormat.OpenXml.Vml.Formulas()
Dim formula1 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "sum #0 0 10800" _
}
Dim formula2 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "prod #0 2 1" _
}
Dim formula3 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "sum 21600 0 #1" _
}
Dim formula4 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "sum 0 0 #2" _
}
Dim formula5 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "sum 21600 0 #3" _
}
Dim formula6 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "if #0 #3 0" _
}
Dim formula7 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "if #0 21600 #1" _
}
Dim formula8 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "if #0 0 #2" _
}
Dim formula9 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "if #0 #4 21600" _
}
Dim formula10 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "mid #5 #6" _
}
Dim formula11 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "mid #8 #5" _
}
Dim formula12 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "mid #7 #8" _
}
Dim formula13 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "mid #6 #7" _
}
Dim formula14 As New DocumentFormat.OpenXml.Vml.Formula() With { _
.Equation = "sum #6 0 #5" _
}
formulasWM.Append(formula1)
formulasWM.Append(formula2)
formulasWM.Append(formula3)
formulasWM.Append(formula4)
formulasWM.Append(formula5)
formulasWM.Append(formula6)
formulasWM.Append(formula7)
formulasWM.Append(formula8)
formulasWM.Append(formula9)
formulasWM.Append(formula10)
formulasWM.Append(formula11)
formulasWM.Append(formula12)
formulasWM.Append(formula13)
formulasWM.Append(formula14)
Dim pathWM As New DocumentFormat.OpenXml.Vml.Path() With { _
.AllowTextPath = True, _
.ConnectionPointType = DocumentFormat.OpenXml.Vml.Office.ConnectValues.[Custom], _
.ConnectionPoints = "#9,0;#10,10800;#11,21600;#12,10800", _
.ConnectAngles = "270,180,90,0" _
}
Dim textPathWM As New DocumentFormat.OpenXml.Vml.TextPath() With { _
.[On] = True, _
.FitShape = True _
}
Dim shapeHandlesWM As New DocumentFormat.OpenXml.Vml.ShapeHandles()
Dim shapeHandleWM As New DocumentFormat.OpenXml.Vml.ShapeHandle() With { _
.Position = "#0,bottomRight", _
.XRange = "6629,14971" _
}
shapeHandlesWM.Append(shapeHandleWM)
Dim lockWM As New DocumentFormat.OpenXml.Vml.Office.Lock() With { _
.Extension = DocumentFormat.OpenXml.Vml.ExtensionHandlingBehaviorValues.Edit, _
.TextLock = True, _
.ShapeType = True _
}
shapetypeWM.Append(formulasWM)
shapetypeWM.Append(pathWM)
shapetypeWM.Append(textPathWM)
shapetypeWM.Append(shapeHandlesWM)
shapetypeWM.Append(lockWM)
Dim shapeWM As New DocumentFormat.OpenXml.Vml.Shape() With { _
.Id = "PowerPlusWaterMarkObject346762751", _
.Style = "position:absolute;margin-left:0;margin-top:0;width:527.85pt;height:131.95pt;rotation:315;z-index:-251655168;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin", _
.OptionalString = "_x0000_s2050", _
.AllowInCell = False, _
.FillColor = "silver", _
.Stroked = False, _
.Type = "#_x0000_t136" _
}
Dim fillWM As New DocumentFormat.OpenXml.Vml.Fill() With { _
.Opacity = ".5" _
}
Dim textPath2WM As New DocumentFormat.OpenXml.Vml.TextPath() With { _
.Style = "font-family:""Arial"";font-size:1pt", _
.[String] = name _
}
shapeWM.Append(fillWM)
shapeWM.Append(textPath2WM)
pictureWM.Append(shapetypeWM)
pictureWM.Append(shapeWM)
runWatermark.Append(runWMProperties)
runWatermark.Append(pictureWM)
Return runWatermark
Catch ex As Exception
ex.Message.ToString()
End Try
End Function
Any suggestions?
I found the solution, missing only the portion of the code that added a paragraph to the document that is
....
Dim para As New DocumentFormat.OpenXml.Wordprocessing.Paragraph
DocumentFormat.OpenXml.Wordprocessing.Paragraph)()
para.Append(r)
Headerpart.Header.Append(para) 'missing code
Headerpart.Header.Save(Headerpart)

LINQ group by with count not returning expected results

I am trying to create a LINQ query that will group all records in the source dataset into a single record summary line showing all objects (except for the unique identifier) and display the count of all the collapsed records. When I run a simple select query I get X records but when I run this query:
Dim qry2 = From j In ( _
From Lines In DLDFDetails _
Select Lines.Site, _
Lines.Service_Name, _
Lines.Product, _
Lines.PDP_Description, _
Lines.First_Name, _
Lines.Last_Name, _
Lines.Email, _
Lines.User, _
Lines.Change_Details, _
Lines.Asset_ID) _
Group j By j.Site, _
j.Service_Name, _
j.Product, _
j.PDP_Description, _
j.First_Name, _
j.Last_Name, _
j.Email, _
j.User, _
j.Change_Details, _
j.Asset_ID.Count _
Into k = Group _
Select New With { _
Site, _
Service_Name, _
Product, _
PDP_Description, _
First_Name, _
Last_Name, _
Email, _
User, _
Change_Details, _
Count}
The count on the summary line shows X-Y. The unique identifier for the dataset is 'Asset_ID'. Can anyone tell me what I'm doing wrong here and what the solution is? Thanks!

Indexed Property Error: Must be Qualified and Arguments Explicitly Supplied

While running the code I've included below I receive the error
"EntityCommandExecutionException was unhandled by user code.
I'm then told to look at the inner exception for details...and there I see under Data:
"In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user."
And under Inner Exception --> Message:
"A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The handle is invalid.)"
The code Visual Studio thinks is at fault is:
Dim qpeople = (From p In dbContext2.PEOPLE _
Where p.PEOPLE_ID = ID _
Order By p.CREATE_DATE Descending _
Select p).FirstOrDefault
The larger code context is:
Protected Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim semester As String = ddlwhSemester.SelectedValue
Dim year As String = txtwhYear.Text
Dim exists As String = "N"
Dim pcsemester As String = ddlSemester.SelectedItem.Text
Dim pcyear As String = ddlYear.SelectedItem.Text
Using dbContext As pbu_housingEntities = New pbu_housingEntities
' Get the list of residents in webHousing.
Dim qresidents = (From p In dbContext.Residents _
Where p.semester = semester _
Where p.year = year _
Select p.people_code_id)
Using dbContext2 As Campus6Entities = New Campus6Entities
' Get the list of students in PowerCampus.
Dim qstudents = (From p In dbContext2.RESIDENCies _
Join a In dbContext2.ACADEMICs _
On a.PEOPLE_CODE_ID Equals p.PEOPLE_CODE_ID _
Where p.ACADEMIC_TERM = pcsemester _
Where p.ACADEMIC_YEAR = pcyear _
Where a.ACADEMIC_TERM = pcsemester _
Where a.ACADEMIC_YEAR = pcyear _
Where a.PROGRAM = "UND" _
Where (a.CLASS_LEVEL = "FR" _
Or a.CLASS_LEVEL = "FRNR" _
Or a.CLASS_LEVEL = "FRST" _
Or a.CLASS_LEVEL = "SO" _
Or a.CLASS_LEVEL = "JR" _
Or a.CLASS_LEVEL = "SR" _
Or a.CLASS_LEVEL = "SR5" _
Or a.CLASS_LEVEL = "Tran") _
Select p.PEOPLE_ID).Distinct
For Each row In qstudents
exists = "N"
For Each res In qresidents
If row.ToString = res.ToString Then
exists = "Y"
End If
Next
If exists = "Y" Then
' Skip adding.
Else
' Add a row.
' Get the ID
Dim ID As String = row
' Get info from PowerCampus
Dim qpeople = (From p In dbContext2.PEOPLE _
Where p.PEOPLE_ID = ID _
Order By p.CREATE_DATE Descending _
Select p).FirstOrDefault
Dim people_code_id As String = qpeople.PEOPLE_CODE_ID
Dim qacademic = (From p In dbContext2.ACADEMICs _
Where p.PEOPLE_CODE_ID = people_code_id _
Where p.ACADEMIC_TERM = pcsemester _
Where p.ACADEMIC_YEAR = pcyear _
Order By p.CREATE_DATE Descending _
Select p.CLASS_LEVEL).FirstOrDefault
Dim qaddress = (From p In dbContext2.ADDRESSes _
Where p.PEOPLE_ORG_CODE_ID = people_code_id _
Where p.ADDRESS_TYPE = "Perm" _
Order By p.CREATE_DATE Descending _
Select p).FirstOrDefault
Dim qdemographics = (From p In dbContext2.DEMOGRAPHICS _
Where p.PEOPLE_CODE_ID = people_code_id _
Order By p.CREATE_DATE Descending _
Select p.GENDER).FirstOrDefault
' Create the new occupant.
Dim newres As New Resident
newres.people_code_id = ID
newres.person_name = qpeople.FIRST_NAME + " " + qpeople.MIDDLE_NAME + " " + qpeople.LAST_NAME
newres.first_name = qpeople.FIRST_NAME
newres.last_name = qpeople.LAST_NAME
newres.class_level = qacademic
newres.gender = qdemographics
newres.semester = semester
newres.year = year
newres.email = qaddress.EMAIL_ADDRESS
newres.create_date = Date.Now
dbContext.Residents.AddObject(newres)
dbContext.SaveChanges()
End If
Next
End Using
End Using
End Sub
Check your db and make sure the primary key is there. I had a similar issue and found that the primary key was not defined. Just a thought, might not be the problem but worth a quick check.
I didn't notice this before but you are setting your ID like this:
Dim ID As String = row
Try converting the ID to a Int before the linq query.

Need Help Resolving SQLDateTime overflow error

Can anyone assist with this error?
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Here's my code:
<DataObjectMethod(DataObjectMethodType.Update)> _
Public Shared Sub UpdateIncident( _
ByVal DateClosed As DateTime, _
ByVal Description As String, _
ByVal original_IncidentID As Integer, _
ByVal original_ProductCode As String, _
ByVal original_DateOpened As DateTime, _
ByVal original_DateClosed As DateTime, _
ByVal original_Title As String, _
ByVal original_Description As String, _
ByVal IncidentID As Integer, _
ByVal ProductCode As String, _
ByVal DateOpened As DateTime, _
ByVal Title As String)
Dim con As New SqlConnection(GetConnectionString)
Dim up As String = "UPDATE Incidents " _
& "SET DateClosed = #DateClosed, " _
& "Description = #Description" _
& "WHERE IncidentID = #original_IncidentID " _
& "AND ProductCode = #original_ProductCode " _
& "AND DateOpened = #original_DateOpened " _
& "AND (DateClosed = #original_DateClosed " _
& "OR DateClosed IS NULL " _
& "AND #original_DateClosed IS NULL) " _
& "AND Title = #original_Title " _
& "AND Description = #original_Description"
Dim cmd As New SqlCommand(up, con)
If DateClosed = #12:00:00 AM# Then
cmd.Parameters.AddWithValue("DateClosed", DBNull.Value)
Else
cmd.Parameters.AddWithValue("DateClosed", DateClosed)
cmd.Parameters("DateClosed").DbType = DbType.DateTime
End If
cmd.Parameters.AddWithValue("Description", Description)
cmd.Parameters.AddWithValue("original_IncidentID", original_IncidentID)
cmd.Parameters.AddWithValue("original_ProductCode", original_ProductCode)
cmd.Parameters.AddWithValue("original_DateOpened", original_DateOpened)
cmd.Parameters("original_DateOpened").DbType = DbType.DateTime
If original_DateClosed = #12:00:00 AM# Then
cmd.Parameters.AddWithValue("original_DateClosed", original_DateClosed)
Else
cmd.Parameters.AddWithValue("original_DateClosed", original_DateClosed)
cmd.Parameters("original_DateClosed").DbType = DbType.DateTime
End If
cmd.Parameters.AddWithValue("original_Title", original_Title)
cmd.Parameters.AddWithValue("original_Description", original_Description)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
SQL Server datetime datatype has range: January 1, 1753, through December 31, 9999
.NET DateTime datatype has range: 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D
You can use SQL Server 2008's new datatype: datetime2
That happens when you have a DateTime that you have not set. The .NET DateTime.MinValue is '01/01/0001 00:00' and the SqlDateTime minimum value is the 1753 value. Just make sure that none of your DateTime's remain unset before sending the data to the database.
UPDATE:
In the method you have defined, add some logic to find and fix DateTime.MinValue's that are passed to you. Please accept my C#,
if (theDateTime < SqlDateTime.MinValue)
{
theDateTime = SqlDateTime.MinValue;
}

the following code is working fine in VS 2010 but giving error in VS2008,WHY? "ClassOne" is a class with Properties IDX,NAME,MOBILENUMBER

Dim obj As New List(Of ClassOne)() From { _
New ClassOne() With { _
Key .IDX = 1206, _
Key .NAME = "Krishna Reddy", _
Key .MOBLIENUMBER = 9494494704L _
}, _
New ClassOne() With { _
Key .IDX = 1242, _
Key .NAME = "Swarupa", _
Key .MOBLIENUMBER = 9441524535L _
}, _
New ClassOne() With { _
Key .IDX = 1236, _
Key .NAME = "Naga Raj", _
Key .MOBLIENUMBER = 9866939656L _
}, _
New ClassOne() With { _
Key .IDX = 1219, _
Key .NAME = "Devika", _
Key .MOBLIENUMBER = 9885735365L _
} _
}
test.DataSource = obj //here "test" is dropdownlist id
test.DataTextField = "NAME"
test.DataValueField = "IDX"
test.DataBind()
Collection initializers are new to VS 2010
http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx

Resources