|
I used SMO to manage SQL server 2005.
I want to modify a column to be same with other column.
I used the following code but it has error while calling Column.Alter() function.
<code>
public void RepairColumns(object dcolumn)
{
try
{
Column d_Column = (Column)dcolumn;
Column l_Column = mServer.Databases[mSMOInfo.DBName].Tables[mSMOInfo.TableIndex].Columns[mSMOInfo.ColumnIndex];
l_Column.Initialize(true);
l_Column.Collation = d_Column.Collation;
l_Column.Computed = d_Column.Computed;
l_Column.ComputedText = d_Column.ComputedText;
l_Column.DataType = d_Column.DataType;
l_Column.Default = d_Column.Default;
l_Column.Identity = d_Column.Identity; string str = d_Column.Properties[1].Name;
l_Column.IdentityIncrement = d_Column.IdentityIncrement;
l_Column.IdentitySeed = d_Column.IdentitySeed;
l_Column.NotForReplication = d_Column.NotForReplication;
l_Column.Nullable = d_Column.Nullable;
l_Column.RowGuidCol = d_Column.RowGuidCol;
l_Column.Rule = d_Column.Rule;
l_Column.RuleSchema = d_Column.RuleSchema;
l_Column.IsPersisted = d_Column.IsPersisted;
l_Column.DefaultSchema = d_Column.DefaultSchema;
l_Column.Alter();
}
catch (SmoException ex)
{
throw ex;
}
}
</code>
If u knows my mistakes, pls point me.
Thanks
|
|
|
|
|
Hi,
could you post the error message? This would help us to understand the problem a bit better.
Regards
Sebastian
|
|
|
|
|
I use adventurework database.
Error is
FailedOperationException - "Alter failed for Column 'SystemInformationID'."
InnerExcetpion - "Modifying the Computed property of the Column object is not allowed. You must drop and recreate the object with the desired property."
|
|
|
|
|
Setting the computed property does only work if you drop and add the column. (As the error message is saying):
http://www.windows-tech.info/15/83beeb9f84f9b78a.php[^]
Do you need to change the computed value of the column? If not, just leave the line
l_Column.Computed = d_Column.Computed;
out.
|
|
|
|
|
Thank for ur reply.
My goal is to change the column properties to be the same with other column.
I already left "Computed" property but an error has been occur with the other property of the column.
|
|
|
|
|
Well... Do you change any default settings of your database server... Can you alter any table in design mode....Let me know.
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
This is me opinion...for this purpose you can use a storedProcedure.
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi
I have written a project in C#.Net 2005 that is connected to SQL Server 2000. The SQL Server Engine is on a server and there are three clients connecting to this server. The application is running on clients. Each minute many requests such as select, insert and ... are sent to the server, through transactions. The default timeout of the SQL Server has not been changed. After 200 requests, for example (the number is random, sometimes more, sometimes less), an error occurs which is:
"Timeout expired, the timeout period elapsed prior to the completion of the operation or the server is not responding"
With no changes in the server name, firewall, network protocol or whatever, the next request after this error, will be sent correctly and the response will be got correctly. Can anyone help me to solve this problem?
Thanks in advance
|
|
|
|
|
I Dont knoq much about MSSQL, i know more MySQL
Do the uses have high response rate to each query?
How many connection can connect to MSSQL simutanosly?
Do you use Windows XP as OS? (Profesional version has a limit to 10 connections. there are some patches to increase that number)
|
|
|
|
|
Is your application connected to the database server on Local / remote environment?
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Have you forgotten to close the DB connection when done, so the connection pool would get exhausted pretty soon?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Are you maing the HUGE mistake of opening a connection to the database in your app when it starts and never closing it until your app closes??
|
|
|
|
|
Hi All,
I want to change a folder permission, by default the folder has "Read" permission , I want to change it to both "Read" & "Write" permission. I tried to use sample programs in MSDN , but some how it is not working, I have attached my source code with this message, If there is any useful pointers to this problems kindly let me know, u r help will be much appriciated
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class DirectoryExample
{
public static void Main()
{
try
{
string DirectoryName = @"C:\Inetpub\ftproot";
Console.WriteLine("Adding access control entry for " + DirectoryName);
AddDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.Write, AccessControlType.Allow);
Console.WriteLine("Removing access control entry from " + DirectoryName);
RemoveDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.Write, AccessControlType.Allow);
Console.WriteLine("Done.");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
DirectoryInfo dInfo = new DirectoryInfo(FileName);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
dInfo.SetAccessControl(dSecurity);
}
public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
DirectoryInfo dInfo = new DirectoryInfo(FileName);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
dInfo.SetAccessControl(dSecurity);
}
}
}
Mike
|
|
|
|
|
I want to have a class name Faculty with some memeber properties. One of the property is a (list of student classes) List<myStudent>. I have a student class (as given below).
When I compile I get the following error:
"Inconsistent accessibility: parameter type 'NestedClass.myStudent' is less accessible than method 'NestedClass.myFacultyMember.AddMyNewItem"
What am I doing wrong?
Cannot we access user defined data types (in this case a class object) within a class from outside?
Thank you in advance!
------------student class-----------------------
<using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NestedClass
{
class myStudent
{
private int studentID;
private string firstName;
private string lastName;
private int age;
public myStudent()
{
}
~myStudent()
{
}
public int StudentID
{
get
{
return studentID;
}
set
{
studentID = value;
}
}
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string LastName
{
get
{
return lastname;
}
set
{
lastname = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
}
}
----------- Faculty Class ---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NestedClass
{
public class myFacultyMember
{
private int facultyID;
private string firstName;
private string lastName;
private int age;
private List<myStudent> lst_Students = new List<myStudent>();
public myFacultyMember()
{
}
~myFacultyMember()
{
}
public int FacultyID
{
get
{
return facultyID;
}
set
{
facultyID = value;
}
}
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
public void AddMyNewItem(myStudent newItem)
{
lst_Students.Add(newItem);
}
}
}>
|
|
|
|
|
myStudent class is private and myFacultyMember is public. You can't expose myStudent class as it is private. To resolve, make it public.
|
|
|
|
|
Hi,
I am trying to read the date from one file into another a new file.
(I know I could just copy it, but I will eventually be processing the data inbetween so I need to do it this way).
So first I create a StreamWriter with the existing path, then I create a StreamReader with the new path, and copy one to the other.
StreamWriter writer = new StreamWriter (existingFilePath);
StreamReader reader = new StreamReader(copiedFilePath);
string strData = reader.ReadToEnd();
Writer.Write(strData);
writer .Close();
reader.Close();
And the end result.... the new file is about 25mb but the old file was only 19mb.
Is this to do with the encoding? Its a PNG file I have selected but ultimatly it could be any file type.
I need to create an EXACT copy! Please help
James
|
|
|
|
|
jehazlam wrote: string strData = reader.ReadToEnd();
jehazlam wrote: PNG file
That is not a string. There is no encoding, it's just raw binary data.
You could use File.ReadAllBytes , for example
|
|
|
|
|
Better you copy the stream in chunks:
StreamWriter writer = new StreamWriter (existingFilePath);
StreamReader reader = new StreamReader(copiedFilePath);
byte[] buffer = new byte[32768];
while (true) {
int read = reader.Read (buffer, 0, buffer.Length);\
if (read <= 0)
break;
writer.Write (buffer, 0, read);
}
writer .Close();
reader.Close();
Best regards,
Jaime.
modified on Monday, October 12, 2009 12:41 PM
|
|
|
|
|
Would this be better?
while (reader.Read (buffer, 0, buffer.Length) > 0 ) {
writer.Write (buffer, 0, read);
}
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
where is the 'read' variable filled?
Best regards,
Jaime.
|
|
|
|
|
It isn't and does not need to be unless you want to compare the number of bytes read with size of buffer. In which case you could do something like:
int read = 0;
while ((read = reader.Read (buffer, 0, buffer.Length)) > 0 ) {
writer.Write (buffer, 0, read);
}
if (read < buffer.Length) {
}
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
riced wrote: It isn't and does not need to be unless you want to compare the number of bytes read with size of buffer
Well, it is always necessary, because on last read, the buffer is partially filled, so the last write is not full buffer contents.
Best regards,
Jaime.
|
|
|
|
|
.
modified 2-Apr-21 5:17am.
|
|
|
|
|
What on earth are you doing ? Creating dlls from resources ? How bizarre. Why create one at c:\ ? Perhaps if you showed us the actual code and told us the actual error message, we could help more ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|