Click here to Skip to main content
15,900,906 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionEquivalent to WSAWaitForMultipleEvents in .NET Pin
lemur26-Aug-09 2:44
lemur26-Aug-09 2:44 
AnswerRe: Equivalent to WSAWaitForMultipleEvents in .NET Pin
Super Lloyd26-Aug-09 3:10
Super Lloyd26-Aug-09 3:10 
GeneralRe: Equivalent to WSAWaitForMultipleEvents in .NET Pin
lemur26-Aug-09 4:45
lemur26-Aug-09 4:45 
GeneralRe: Equivalent to WSAWaitForMultipleEvents in .NET Pin
Super Lloyd26-Aug-09 5:27
Super Lloyd26-Aug-09 5:27 
GeneralRe: Equivalent to WSAWaitForMultipleEvents in .NET Pin
lemur26-Aug-09 10:45
lemur26-Aug-09 10:45 
AnswerRe: Equivalent to WSAWaitForMultipleEvents in .NET Pin
Mark Salsbery26-Aug-09 8:04
Mark Salsbery26-Aug-09 8:04 
Questionfinding parent child relation in dataset Pin
TARAK NATH ROY25-Aug-09 21:17
TARAK NATH ROY25-Aug-09 21:17 
QuestionHow can I drop and recreate a default constraint using smo? Pin
bobishkindaguy25-Aug-09 13:27
bobishkindaguy25-Aug-09 13:27 
I'm almost there.

The problem: Using smo, I'm having trouble re-creating a DefaultConstraint on a column after dropping it.
Where this stems from: I need to change a column from nvarchar(x) to nvarchar(max).

(The ms help is useless, showing no examples for working with default constraints. No searches show people using smo to solve this.)

The conceptual problem is that you can't change a column's size if a "DefaultConstraint" exists on the column. You must drop the DefaultConstraint, then change the size of the column, and then re-create the DefaultConstraint.

Variables not shown: The variable "AColumn" below has been populated with a smo column object (Name:"SsGradeString"), and the variable "Size" is the desired size to change the column to.

The error occurs on AColumn.AddDefaultConstraint(DName), error message:"Column SsGradeString already has a default."

I tried doing Table.Alter, Column.Alter, DefaultConstraint.Alter (after the .Drop), but I get: "Cannot access properties or methods for the Microsoft.SqlServer.Management.Smo.DefaultConstraint '[DF_ADVSessions_SsGradeString]', because it has been dropped."

'preserve existing values for re-creation of DefaultConstraint
'NOTE: AColumn is the column we are working with and Size is the new size to set.
Dim DName As String = ""
Dim DText As String = ""
Dim DefaultConstraintWasThere As Boolean = False

'remove DefaultConstraint if it exists
If AColumn.DefaultConstraint IsNot Nothing Then
  DefaultConstraintWasThere = True
  DName = AColumn.DefaultConstraint.Name
  DText = AColumn.DefaultConstraint.Text
  AColumn.DefaultConstraint.Drop()
  'tried doing various "Alter"s here but none work,
  'citing that the DefaultConstraint's properties cannot be accessed.
End If

'make the desired change to the column property
AColumn.DataType.MaximumLength = Size

'recreate the DefaultConstraint if there was one
If DefaultConstraintWasThere Then
  Try
    'error is occurring here
    AColumn.AddDefaultConstraint(DName)
    AColumn.DefaultConstraint.Text = DText
  Catch ex As Exception
    Stop
  End Try
End If

AnswerRe: How can I drop and recreate a default constraint using smo? Pin
Murat SAVAS15-Dec-09 8:03
Murat SAVAS15-Dec-09 8:03 
GeneralRe: How can I drop and recreate a default constraint using smo? Pin
bobishkindaguy15-Dec-09 14:12
bobishkindaguy15-Dec-09 14:12 
Questioncrazy COM idea Pin
srcarr25-Aug-09 12:04
srcarr25-Aug-09 12:04 
QuestionCode obfuscation Pin
koleraba25-Aug-09 11:09
koleraba25-Aug-09 11:09 
AnswerRe: Code obfuscation Pin
N a v a n e e t h25-Aug-09 20:04
N a v a n e e t h25-Aug-09 20:04 
QuestionWinXP Home Can't Use Subfolder as Source for Picture Pin
Hypermommy25-Aug-09 8:58
Hypermommy25-Aug-09 8:58 
AnswerRe: WinXP Home Can't Use Subfolder as Source for Picture Pin
Henry Minute26-Aug-09 5:08
Henry Minute26-Aug-09 5:08 
GeneralRe: WinXP Home Can't Use Subfolder as Source for Picture Pin
Hypermommy26-Aug-09 5:11
Hypermommy26-Aug-09 5:11 
GeneralRe: WinXP Home Can't Use Subfolder as Source for Picture Pin
Henry Minute26-Aug-09 5:19
Henry Minute26-Aug-09 5:19 
GeneralRe: WinXP Home Can't Use Subfolder as Source for Picture Pin
Hypermommy26-Aug-09 6:09
Hypermommy26-Aug-09 6:09 
QuestionInstall software microphone Pin
TripShock24-Aug-09 2:11
TripShock24-Aug-09 2:11 
QuestionWhy does backgroundworker complete event is fired in other thread, instead of the one started it? [modified] Pin
Carl00723-Aug-09 22:53
Carl00723-Aug-09 22:53 
AnswerRe: Why does backgroundworker complete event is fired in other thread, instead of the one started it? Pin
Alan N24-Aug-09 1:17
Alan N24-Aug-09 1:17 
AnswerRe: Why does backgroundworker complete event is fired in other thread, instead of the one started it? Pin
Luc Pattyn24-Aug-09 1:46
sitebuilderLuc Pattyn24-Aug-09 1:46 
AnswerRe: Why does backgroundworker complete event is fired in other thread, instead of the one started it? Pin
Luc Pattyn26-Aug-09 0:05
sitebuilderLuc Pattyn26-Aug-09 0:05 
QuestionGetting mscorlib.Authentication Failure error Pin
V K 223-Aug-09 21:13
V K 223-Aug-09 21:13 
QuestionVB.NET PropertyGrid Categories Pin
NFranks23-Aug-09 15:06
NFranks23-Aug-09 15:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.