Microsoft MVP성태의 닷넷 이야기
내솔루션 판매 시 1.0.0.0 폴더와 Sqlite 배포 [링크 복사], [링크+제목 복사],
조회: 10698
글쓴 사람
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]

... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...
NoWriterDateCnt.TitleFile(s)
1212조광훈2/13/201416264ISAPI 필터에서 커스텀 헤더 정보 추가 [1]파일 다운로드1
1211조광훈2/12/201420343isapi 필터 로드 오류 [2]
1208박지호2/9/201424413[오타] 시작하세요 C# 프로그래밍 p.267 ~ 350 [1]
1207임동찬2/5/201418608Web페이지에서 .net application 실행시키는 방법 [3]
1206신지환2/3/201419909visual sourcesafe(internet) 체크인 에러 [1]
1205박지호2/2/201422206[오타] 시작하세요 C# 프로그래밍 p.199 ~ 202 [1]
1204김태훈1/27/201433207Windows Service 오류 문의입니다. [2]
1203박지호1/26/201423856[오타] 시작하세요 C# 프로그래밍 p.131, 157, 180 [1]
1202이창주1/24/201425558[질문] Windows Error Reporting [8]
1201김나리1/21/201418494[시작하세요 C# 프로그래밍] 비동기 호출 [1]
1200박지호1/19/201423592[오타] 시작하세요 C# 프로그래밍 p.76 [1]
1199윤종현1/9/201419225p654 의 비동기 관련 설명 [3]
1198초이1/4/201418944웹서비스 WSDL 생성및 프록시 클래스 생성 관련 질문입니다. [1]
1196박현수1/2/201417657[WCF] Client 호출 방법 [2]
1195박현수12/23/201317612[WCF] 클라이언트의 호출실패(IIS이용) [4]파일 다운로드1
1191박주만12/18/201324630C++ Dll 에서 C# 의 PictureBox이미지 변경문제 [1]
1193박주만12/19/201318631    답변글 [답변]: C++ Dll 에서 C# 의 PictureBox이미지 변경문제 [2]파일 다운로드1
1190정진호12/10/201316770비동기로 실행할수 있도록 Custom Attribute 를 만들고 싶습니다. [1]
1189Youn...12/10/201317088책을 사기전에 궁금한것이 있습니다. [1]
1188이민석12/5/201318443ocx 를 C#에서 마샬링관련 질문입니다.. [2]파일 다운로드1
1187이성환12/3/201319653WPF WebBrowser control의 자식 창이 close 되기 전 Navgate 재호출 문제 [2]파일 다운로드1
1186박종혁12/2/201317625책의 예제 중에 result 변수가 할당 되었지만 사용되지 않았다고 오류가 납니다!! [1]
1185박은희11/27/201320731멀티바이트로 개발한 프로그램을 유니코드로 변경시 쉽게 처리 하는법 [2]파일 다운로드1
1183박현수11/20/201317553WCF에서 web.config appsetting 읽기 [1]
1184박현수11/20/201318425    답변글 [답변]: WCF에서 web.config appsetting 읽기 [3]파일 다운로드1
1182유창우11/16/201327462자마린이 궁금... [8]
... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...