문제

마이그레이션을위한 도구가 있습니까? sqlite 데이터베이스로 SQL 서버 (구조와 데이터 모두)?

도움이 되었습니까?

해결책

sqlite 명령 줄에서 실행할 .dump 옵션이 있습니다. 나는 사용하는 것을 선호하지만 SQLITE 데이터베이스 브라우저 SQLITE 데이터베이스 관리 응용 프로그램. 구조와 내용을 거의 무엇이든 읽을 수있는 .SQL 파일로 내보낼 수 있습니다. 파일> 내보내기> 데이터베이스로 SQL 파일.

다른 팁

나는 이것이 오래된 실이라는 것을 알고 있지만,이 솔루션도 여기에 있어야한다고 생각합니다.

  • SQLITE 용 ODBC 드라이버를 설치하십시오
  • x64 또는 c : windows syswow64 odbcad32.exe x86 용 Odbcad32를 실행하십시오.
  • SQLITE3 ODBC 드라이버를 선택하는 시스템 DSN 작성
  • 그런 다음 데이터베이스 이름이 filepath to sqlite 데이터베이스 인 양식을 작성합니다.

그런 다음 SQL Server에서 Sysadmin에서 실행됩니다

USE [master]
GO
EXEC sp_addlinkedserver 
   @server     = 'OldSQLite', -- connection name
   @srvproduct = '',          -- Can be blank but not NULL
   @provider   = 'MSDASQL', 
   @datasrc    = 'SQLiteDNSName' -- name of the system DSN connection 
GO

그런 다음 쿼리를 일반 사용자로 실행할 수 있습니다.

SELECT * INTO SQLServerDATA FROM openquery(SQLiteDNSName, 'select * from SQLiteData')

또는 같은 것을 사용할 수 있습니다 이것 더 큰 테이블의 경우.

sqlite .dump 명령은 데이터베이스의 전체 내용을 ASCII 텍스트 파일로 출력합니다. 이 파일은 표준 SQL 형식이므로 모든 SQL 데이터베이스로 가져올 수 있습니다. 이 페이지에 대한 자세한 내용 : sqlite3

SQLITE-MANAGER, Firefox 추가 기능 : SQL 라이트 데이터베이스를 SQL 스크립트로 내보낼 수 있습니다.

데이터베이스> 내보내기 데이터베이스> 파일로 내보내기

(수정 Firefox 35 Bugg는 다음 웹 페이지를 나타내는 확장 코드를 수정해야합니다.옵션 SQLITE 관리자 모듈을 수정하는 방법은 작동합니다.)

명령 줄 :

sqlite3 DB_name .dump > DB_name.sql

SQLite 데이터베이스를 SQL 스크립트로 내보내십시오.

URL에서 : http://doc.ubuntu-fr.org/sqlite.

아이디어는 다음과 같은 일을 수행합니다 .- SQL Lite에서 Squema를보고 Create Table 명령을 가져옵니다. -SQL Server에서 SQL을 구문 분석 - 각 행에 대한 삽입 문장을 생성합니다. (구문 분석 SQL도)

이 코드는 유형 데이터를 감지하지 못하고 @parameter 및 명령 개체를 사용하지 않기 때문에 베타입니다.

(참조 삽입 및 System.Data.sqlite;)가 필요합니다.)

C#:이 코드 (또는 Neccesari)를 헤드 CS에 삽입하십시오.

시스템 사용;

System.collections.generic 사용;

system.text 사용;

System.Data 사용;

system.data.sqlclient 사용;

System.data.sqlite 사용;

System을 사용하여 스레딩;

system.text.regularexpressions 사용;

System.io 사용;

log4net 사용;

System.net 사용;

    public static Boolean SqLite2SqlServer(string sqlitePath, string connStringSqlServer)
    {
        String SqlInsert;
        int i;
        try
        {

            string sql = "select * from sqlite_master where type = 'table' and name like 'YouTable in SQL'";
            string password = null;
            string sql2run;
            string tabla;
            string sqliteConnString = CreateSQLiteConnectionString(sqlitePath, password);
            //sqliteConnString = "data source=C:\\pro\\testconverter\\Origen\\FACTUNETWEB.DB;page size=4096;useutf16encoding=True";

            using (SQLiteConnection sqconn = new SQLiteConnection(sqliteConnString))
            {



                sqconn.Open();

                SQLiteCommand command = new SQLiteCommand(sql, sqconn);
                SQLiteDataReader reader = command.ExecuteReader();

                SqlConnection conn = new SqlConnection(connStringSqlServer);
                conn.Open();
                while (reader.Read())
                {
                    //Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
                    sql2run = "" + reader["sql"];
                    tabla = "" + reader["name"];

                    /*
                    sql2run = "Drop table " + tabla;
                    SqlCommand cmd = new SqlCommand(sql2run, conn);                       
                    cmd.ExecuteNonQuery();
                    */



                    sql2run = sql2run.Replace("COLLATE NOCASE", "");
                    sql2run = sql2run.Replace(" NUM", " TEXT");
                    SqlCommand cmd2 = new SqlCommand(sql2run, conn);
                    cmd2.ExecuteNonQuery();


                    // insertar los datos.
                    string sqlCmd = "Select *  From " + tabla;
                    SQLiteCommand cmd = new SQLiteCommand(sqlCmd, sqconn);
                    SQLiteDataReader rs = cmd.ExecuteReader();
                    String valor = "";
                    String Valores = "";
                    String Campos = "";
                    String Campo = "";
                    while (rs.Read())
                    {
                        SqlInsert = "INSERT INTO " + tabla;
                        Campos = "";
                        Valores = "";
                        for ( i = 0; i < rs.FieldCount ; i++)
                        {

                            //valor = "" + rs.GetString(i);
                            //valor = "" + rs.GetName(i);
                            Campo = "" + rs.GetName(i);
                            valor = "" + rs.GetValue(i);

                            if (Valores != "")
                            {
                                Valores = Valores + ',';
                                Campos = Campos + ',';
                            }
                            Valores = Valores + "'" + valor + "'";
                            Campos = Campos + Campo;
                        }
                        SqlInsert = SqlInsert + "(" + Campos + ") Values (" + Valores + ")";
                        SqlCommand cmdInsert = new SqlCommand(SqlInsert, conn);
                        cmdInsert.ExecuteNonQuery();


                    }


                }

                }
            return true;
        } //END TRY
        catch (Exception ex)
        {
            _log.Error("unexpected exception", ex);

            throw;

        } // catch
    }

안드로이드의 경우.

adb root
adb shell
cd /data/com.xxx.package/databases/
sqlite3 db_name .dump >dump.sql
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top