Tuesday, January 6, 2009

SQL Server 2008: "Saving changes is not permitted"

When trying to save a table in SQL Server 2008 error comes up "Saving changes is not permitted" The statement is like this
Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.
While searching on the net i found out that there are some more chnages which we do on the table in SQL server 2008 and that will cause same error above.

Below are some of the
  1. change the Allow Nulls
  2. setting for a column.
  3. reorder columns in the table.
  4. change the column data type.
  5. add a new column.

This Warning message pops up because we create a New schema for the Table. This schema change might loose already existing data in the table it will also change the meta data of the table.
To get rid of this waring message

  1. Open SQL Server Management Studio (SSMS).
  2. On the Tools menu, click Options. In the navigation pane of the Options window,
  3. click Designers. Select or clear the Prevent saving changes that require the table re-creation check box, and then click OK.

If you disable this option, you are not warned when you save the table that the changes that you made have changed the metadata structure of the table. In this case, data loss may occur when you save the table.

Monday, January 5, 2009

Create a text file using Dataset or Datatable in C#

I am currently working with the Dataset. I had a requirement in which i have to write a functionality in which all the data is written to the text file. The requirement is like create a text file and all the columns will be separated by tilde symbol. Below is the sample code which will solve the problem.
void CreateTextfile(string FilePath,Datatable dt)
{
int i = 0;
StreamWriter swTextFile= null;
try
{
swTextFile= new StreamWriter(filePath, false);
for (i = 0; i < dt.Columns.Count - 1; i++)
{
swTextFile.Write(dt.Columns[i].ColumnName + " ");
}
swTextFile.Write(dt.Columns[i].ColumnName);
swTextFile.WriteLine();
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
for (i = 0; i < array.Length - 1; i++)
{
swTextFile.Write(array[i].ToString() + "~");
}
swTextFile.Write(array[i].ToString());
swTextFile.WriteLine();
}
swTextFile.Close();
}
catch (Exception ex)
{
throw ex;
}
}

Friday, January 2, 2009

NSIS Script for 64 Bit Machine

Today i was working on the NSIS scripts. In this perticular script i have to write the registry values in the system. There is a function call WriteRegExpandStr.
syntax: WriteRegExpandStr HKLM "Software\ProductName" "dbServer" "anyvalue"
This function will write the registry value "anyvalue" in the registry with the keyname as dbserver. Now this works good when we have the 32 bit machine. Now when you have 64 bit machine and then this value you won't see under "Software\ProductName" . By default it will be created under the "Software\Wow6432Node\ProductName" . In my case my application reading the data from the Software\ProductName and there is no data as the registry values are written under Software\Wow6432Node\ProductName . Just to keep my code in tacke i have write a small function which will check if the machine is 64 bit or a 32 bit. Depend on the machine type it will get and update the data from the registry. Below is the code
public static string CheckIf64BitOS()
{
int bits = IntPtr.Size * 8;
return bits.ToString();
}

if (CheckIf64BitOS().Equals("64")) {//Write a logic for 64 bit}
if (CheckIf64BitOS().Equals("32")) {//Write a logic for 32 bit}

Hope this will solve your problem.

Friday, October 31, 2008

System.Data.DataSetExtensions


System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.DataSetExtensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Data.DataSetExtensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Hi friend

above is the error comes up in one of my current project. This is a particular problem comes when we convert our 1.1 or 2.0 framework application to 3.5 framework. In my project my client is having problem while installing our application on the 64 bit machine. I have started in the intention that i will just install the application and that's it. But it took half an hour or so to just install the application with one fatal error 1603.  This error occur because of three reason given by MSDN

The folder that you are trying to install the Windows Installer package to is encrypted.
The drive that contains the folder that you are trying to install the Windows Installer package to is accessed as a substitute drive.
The SYSTEM account does not have Full Control permissions on the folder that you are trying to install the Windows Installer package to. You notice the error message because the Windows Installer service uses the SYSTEM account to install software.

But i was just happy to ignore this error as my application was installed even after this error.  Now the only problem left with the reports. when ever i am try to create the reports it give me error like above.

While checking for the solution i come to know that the client don't have the hot fix for the 3.5 framework. In the above image you can see the properties. There is a red color circle which shows the version as 3.5.0.0 But the client system has only run time of the 3.5 and in the run time this particular .dll file is not present. I am getting this error as i am using this .dll file for the Type Data set. 

Solution. Just download the framework 3.5

http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6&displaylang=en

and run it on the system. that's it.

   


Monday, September 15, 2008

Login Error in subreports with Crystal Reports

I am a fan of crystal reports. When ever it is feasible i want to use the Crystal report in my .net application whether it is window or web application. 
While working with one of my window application i got this weird error. It ask me for login in the database. That also happened with my reports which i changed recently.  The reports were working good till they were on my development system. It started giving problem when they are deployed on client machine. 
My client enviourment we have VS 2008 IDE too. So i opened the Report and went in the Dataset and check if it is pointing to correct XSD or not. I am using XSD (Type data set) in  all my crystal reports. Now when i click on the verify database the message came up "Data base is up to Date" . But after that the message box came up for selecting the XSD. I have selected the XSD and then the report start working as expected. 
With all these exercise i came to know that there is some problem with the XSD. The only way to find out the problem is this way
1) Open the .rpt file
2) Go to field Explorer
3) Right Click on database field and then Database Expert
4) Create New connection 
5) Click On ADO.net 
6) It will ask you to select the class
7) If you have some table already  selected then you can just right click the table and see the properties. if Visual Studio Data Class name  is set for the Local directory something like c:\project..
that is the root of the problem. So you have to make it from the project not from the local directory.

 

Wednesday, September 10, 2008

Distinct records in datatable

Here is the easiest way to create a table with the distinct records. I have to add the currency symbols with the Currency name in the brackets. If these currency name was not the constraint then it was be really easy for me to add the items in the Combobox. I was able to add the items in the comboox and before adding just giving this condition 
if (ddlCurrencySymbol.Items.Contains("Textvalue")) continue;
Solve my purpose. But now the problem was i have to add the Currency name also in the list. So i can't just adding the name and use the above condition because it will create Euro for many countries. 

Now here what i have done to solve this issue.
I create two functions and use them to get rid of the Extra values.

public void SelectDistinctCurrency(string TableName, DataTable Table1, string CurrencyName)
        {
            DataTable dt = new DataTable(TableName);
            dt.Columns.Add(CurrencyName, SourceTable.Columns[CurrencyName].DataType);
            dt.Columns.Add("Text", SourceTable.Columns[CurrencyName].DataType);
            object FinalValue= null;
            foreach (DataRow dr in SourceTable.Select("", CurrencyName))
            {
                if (FinalValue == null || !(ColumnEqual(FinalValue, dr[FieldName])))
                {
                    FinalValue = dr[CurrencyName];
                    dt.Rows.Add(new object[] { FinalValue, dr["Text"] });
                }
            }
            ddlCurrencySymbol.DataSource = dt;
            ddlCurrencySymbol.DisplayMember = "Text";
            ddlCurrencySymbol.ValueMember = "Value";
        }
        private bool ColumnEqual(object A, object B)
        {

            if (A == DBNull.Value && B == DBNull.Value) 
                return true;
            if (A == DBNull.Value || B == DBNull.Value) 
                return false;
            return (A.Equals(B));  
        }

Hope this will hep you out.

Tuesday, September 9, 2008

Winform Size

Hi friends 
i fond one intresteing thing today. It was increaing the height of the window form in Visual studio. I have oen collegue he cam up with unique problem. he ask me how to increase the size of the Window form in the VS. The obvoius answer was just go to properties and add the number and the form will increase of that size. But to my surprize what ever value we enter it will revert back to 768 Pixel.  Now how to increase in the size if i want that to 1000. 
The trick was just  change the resolution of your system and then increae the size. now revert back to old resolution this increased sized won't revert back. It will remain 1000 Pixel only :)