Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code lines(I am still a rookie. :)) ;
I was trying to export the table on C# so after searching and trying hours I got this problem :|

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management;

//Here my script codes
 private void Button_Click(object sender, EventArgs e)
        {
            Server server = new Server("(local)"); 

          Database sourceDB = server.Databases["KaynakDB"];//"Kaynak" means Source
            Table table = sourceDB.Tables["AnaTablo"];//"AnaTablo" means main table

         Database targetDB = server.Databases["KopyalanacakDB"];//Target Database

            foreach (String s in table.Script())

               targetDB.ExecuteNonQuery(s);
            


           
            
        }


Error Message :

C#
FailedOperationException was unhandled

An unhandled exception of type 'Microsoft.SqlServer.Management.Smo.FailedOperationException' occurred in Microsoft.SqlServer.Smo.dll



Am I missing something?
(And Sorry for my low-graded English.)
Thanks.
Posted
Comments
[no name] 18-Sep-13 8:47am    
http://technet.microsoft.com/en-us/library/ms162127.aspx
Cenkay Vergili 18-Sep-13 9:03am    
Thank you. That was really helpful.

1 solution

Problem Solved! :P

-Change your .NET Framework of your program to 4 .
Then
XML
You gotta change your App.config like that ;

    <?xml version="1.0"?>
    <configuration>
        <startup>

        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
    </configuration>

to

    <?xml version="1.0"?>
    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">

        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
    </configuration>

(If still does not work you can try to change your Platform Target "Properties > Build > Platform Target" to 64x or 86x(The same as your Refences) .)
It worked for me!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900