Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 varchar to nvarchar

Author  Topic 

sachin7ul
Starting Member

1 Post

Posted - 2007-08-07 : 05:50:44
Hi All,

I am trying to replace all stored procedure paramaters of type 'varchar' to 'nvarchar' for this I have written a simple program as follows - however it does not update the parameter type.


Server server = new Server(@"PCPUNE24\SQLEXPRESS");
Database db = server.Databases[@"Flowmaster Benchmark"];
if ( db == null )
return;
for ( int i = 0; i < db.StoredProcedures.Count; i++ )
{
StoredProcedure sproc = db.StoredProcedures[i];

if ( sproc.IsSystemObject )
continue;

for(int j = 0;j < sproc.Parameters.Count;j++)
{
StoredProcedureParameter para = sproc.Parameters[j];

if ( para.DataType.SqlDataType != SqlDataType.VarChar )
continue;
Console.WriteLine( sproc.Name + "\t" + para.Name + "\t" + para.DataType.MaximumLength );
sw.WriteLine( sproc.Name + "\t" + para.Name + "\t" + para.DataType.MaximumLength );
int maxleng = para.DataType.MaximumLength;
int prec = para.DataType.NumericPrecision;
int nscale = para.DataType.NumericScale;

DataType datatype = new DataType();
datatype.MaximumLength = maxleng;
datatype.SqlDataType = SqlDataType.NVarChar;
para.DataType = datatype;
sproc.Alter();
}
}


Can someone help me with whats wrong with this code?
   

- Advertisement -