Microsoft MVP성태의 닷넷 이야기
내솔루션 판매 시 1.0.0.0 폴더와 Sqlite 배포 [링크 복사], [링크+제목 복사],
조회: 10738
글쓴 사람
guest
홈페이지
첨부 파일
 

내솔루션의 exe파일을 타인이 설치 후 타인 컴퓨터 내에 Sqlite에 Write 기능이 필요한 경우

1) 타인 컴퓨터에 Write기능이 허용은 제한적이어야 하므로 타인 컴퓨터의 AppData/Local/1.0.0.0폴더만
   원칙적으로 사용할 수 있다. 이것은 Application.LocalUserAppDataPath를 의미한다.

2) 타인 컴퓨터에 프로그램설치 시 1.0.0.0 폴더가 생성되지 않는 경우도 있으므로
    Directory.CreateDirectory(destDirName)로 폴더를 생성해야 한다

위의 내용이 맞다면 만약 타인 컴퓨터에 1.0.0.0 폴더가 숨김이 적용된 상태여도
위 절차는 적용될 수 있는지요?









[최초 등록일: ]
[최종 수정일: 4/17/2023]


비밀번호

댓글 작성자
 



2023-04-17 08시29분
[guest] 질문처럼하지 않고 아래처럼 하면 자동으로 Sqlite db파일이 형성되는 지요?

public async static void InitializeDatabase()
{
     await ApplicationData.Current.LocalFolder.CreateFileAsync("sqliteSample.db", CreationCollisionOption.OpenIfExists);
     string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
     using (SqliteConnection db =
        new SqliteConnection($"Filename={dbpath}"))
    {
        db.Open();

        String tableCommand = "CREATE TABLE IF NOT " +
            "EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY, " +
            "Text_Entry NVARCHAR(2048) NULL)";

        SqliteCommand createTable = new SqliteCommand(tableCommand, db);

        createTable.ExecuteReader();
    }
}
[guest]
2023-04-17 09시45분
그냥... 직접 해보시면 것이 더 빠르지 않을까요? 원래 질문의 경우, 간단하게 폴더를 숨김 처리한 다음 그 안의 파일이 열리는지 테스트해 보시면 될 듯하고, 덧글의 질문 같은 경우에도 코드까지 만들었으니 지금 당장 해보시면 될 것 같은데요.
정성태
2023-04-18 09시58분
[guest] 여러 번 다 해봤습니다ㅜㅜ 좀 더 나은 접근법을 찾는 것이죠
고수들의 접근법이 궁금해서요

[1.0.0.0 - 이미지]
이미지가 pixabay.com처럼 수백만장이면 배포 시 1.0.0.0을 사용할 필요없지만
호스팅서비스를 비용 등의 이유로 안만드는 경우

이미지가 1만장 정도되는 경우 이 걸 user가 이용하도록 허용할 때
저렇게 하는게 스탠다드한 접근법인지요?
[guest]
2023-04-18 03시47분
[guest] [초보전용] exe파일 만들기 전에 db작업을 하는 경우
db를 repos폴더에 만들지 마시고(C:\Users\여러분\source\repos\여러분플젝이름
db는 C:\Users\여러분\AppData\Local\여러분플젝이름\여러분플젝이름\1.0.0.0\test.sqlite에
 만들면 좋을 듯 합니다 Application.LocalUserAppDataPath가 1.0.0.0주소네요

[db만들기/table생성 코드]
MessageBox.Show(Application.LocalUserAppDataPath);
string path1 = Path.Combine(Application.LocalUserAppDataPath, "synccc.sqlite");
string dbConnectionString = @"Data Source=" + path1 + ";Version=3;";

if (!System.IO.File.Exists(path1))
{
    SQLiteConnection.CreateFile(path1);

    using (SQLiteConnection sqliteConnection = new SQLiteConnection(path1))
    {
        sqliteConnection.Open();

        using (SQLiteCommand sqliteCommand = new SQLiteCommand(sqliteConnection))
        {
             sqliteCommand.CommandText = @"CREATE TABLE Cars(Id INTEGER PRIMARY KEY, Name TEXT, Price INT)";

              sqliteCommand.ExecuteNonQuery();
        }

        sqliteConnection.Close();
    }
}
[guest]
2023-04-21 08시22분
[gwise] exe파일이 설치됐다면 그 폴더에는 read/write 권한이 있다는 얘기겠죠. 그럼 그 폴더에 sqlite을 생성하면 됩니다.

생성은 크게 초기에 하는 것과 컬럼 수정으로 나눠서 보면 됩니다.
1. 생성
생성은 매번 호출 될 터이니 아래 처럼 if not exists 를 해주시고
string sql = string.Empty;
//Item
sql = @"CREATE TABLE if not exists Item(
        [ItemId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
        [ItemName] TEXT NOT NULL,
        [Barcode] TEXT NOT NULL DEFAULT(''),
        [Sku] TEXT NOT NULL DEFAULT(''),
        [Location] TEXT NOT NULL DEFAULT(''),
        [Category] TEXT NOT NULL DEFAULT(''),
        [UnitCost] NUMERIC NOT NULL DEFAULT(0),
        [UnitPrice] NUMERIC NOT NULL DEFAULT(0),
        [IsUsed] TEXT NOT NULL DEFAULT('Y'),
        [Comment] TEXT NOT NULL DEFAULT(''),
        [CreatedDate] TEXT NOT NULL DEFAULT(strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')),
        [CreatedEmp] TEXT NOT NULL DEFAULT(''),
        [ModifiedDate] TEXT NOT NULL DEFAULT(strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')),
        [ModifiedEmp] TEXT NOT NULL DEFAULT(''),
        [AddColumns] TEXT NOT NULL DEFAULT('')
    )";
new SqliteCommand(sql, conn).ExecuteNonQuery();

sql = @"CREATE Unique INDEX if not exists [Item.idx1] ON Item ([ItemName])";
new SqliteCommand(sql, conn).ExecuteNonQuery();

2. 컬럼 추가
컬럼이 추가 됐는지 확인 하고
public bool AddColumnIfExist(string table, string column)
{
    using (SqliteConnection connection = CreateConnection())
    {
        SqliteCommand selectCommand = new SqliteCommand();
        selectCommand.Connection = connection;
        selectCommand.CommandText = $"PRAGMA table_info({table});";
        SqliteDataReader reader = selectCommand.ExecuteReader();

        while (reader.Read())
        {
            if (column.Equals(reader["name"]))
            {
                Console.WriteLine("OK");
                return true;
            }
        }
    }
    return false;
}

없다면 컬럼 추가
public int AlterTableAddColumn(string table, string column, string type)
{
    int result;
    using (SqliteConnection connection = CreateConnection())
    {
        SqliteCommand selectCommand = new SqliteCommand();
        selectCommand.Connection = connection;
        selectCommand.CommandText = $"ALTER TABLE {table} ADD {column} {type};";
        result = selectCommand.ExecuteNonQuery();
    }

    return result;
}

이렇게 하면 됩니다.
[guest]

... 61  62  63  64  65  66  67  68  69  [70]  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
818개발돌이8/14/200917254ActiveX개발한 dll을 임베디드 할때 UI에 대한 질문 [1]파일 다운로드1
817채승수8/13/200916556클릭원스 관련 질문드립니다.~ [1]
816박진오7/29/200915869다국어 사이트의 컨텐츠 저장 방식에 대해.. [2]
814서광원7/16/200924775IWebBrowser2를 이용한 프로그램에서 javascript의 alert 창 무시하는 법? [1]
813윤상균7/16/200915667비관리코드와의 상호운용에서 마샬링 질문 [1]
812김현우7/13/200916151usercontrol은 mdi container가 될수 없는데 이를 구현할 방법은 무엇일런지요? [2]
811조민수7/3/200915614MSDN Magazine 한글화 않되나요? [1]
810세경6/29/200921058SmartClient Vista 64bit IE7 [4]
809윤석준6/24/200921019IE -nomerge 옵션으로 새창을 열려고 합니다. [1]
808한승훈6/4/200919833dll import하기 위해 struct 구성시에 struct가 struct를 가지고 있고 포함된 struct가 ByValArray형태일때 해결 [1]
806곰티5/26/200917993defcon pro 설치 원천 봉쇄 방법 문의 [3]
802채승수5/8/200917022신뢰사이트 등록/적용에 관해 질문드립니다. [1]
801채승수4/15/200917892IE8 새세션을 코드로 구현할수 없을까요 [1]
800신동열4/7/200918073IE8에서 스마트 클라이언트 로딩 문제 [2]
7993/27/200921854이벤트 로그 오류 [1]
798천해3/26/200918348IE8.0 에 관해 질문 드립니다. [2]
797궁금..3/23/200918260IE 8 관련 질문.. [2]
796정성태3/20/200916885스마트클라이언트와 ActiveX에 관한 질문 [1]
795김기용3/19/200916517[질문] DHTML 다이얼로그 관련 [2]
794박평옥3/18/200916839Vista에서 URL Shortcut 실행 시 SetSite가 두 번 호출되는 증상에 관해 조언 부탁드립니다. [2]
792김기용3/12/200915978어제 세미나 잘 들었습니다. 질문사항이 있습니다.(ie8 마이그레이션 관련) [4]
791vb표성백2/17/200921471ATL 로 만든 COM 에 문자열 전달하기! C#에서 어떻게 하나요? [1]
790고민중2/16/200914111vista에 vs2005를 사용중입니다. [1]
789지언2/14/200916157MFC & C#(COM) 호환 관련하여 답변좀 부탁드립니다 [2]
788하루야채2/3/200915125스마트클라이언트 Windowless 설정에 대해서 문의드립니다. [2]
787궁금이2/2/200915602TFS 관련하여 질문드리고자 합니다. [2]
... 61  62  63  64  65  66  67  68  69  [70]  71  72  73  74  75  ...