 |
|
ถามการทำตัว install โปรแกรม C# หน่อยครับ จะทำตัว install โดยมี ดาต้าเบส |
|
 |
|
|
 |
 |
|
สงใส <--- ???
sql server ก็บอกอยู่ว่า server
ก็สร้าง connection ไปที่ server สิ
|
 |
 |
 |
 |
Date :
2013-04-09 14:50:02 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
windows app ตอนเขียน sql server 2008 มันมีดาต้าเบสที่เราสร้างมันจึงติต่อกับฐานข้อมูลที่เราเขียนได้
ที่นี้ ผมสร้าง ตัว install เพื่อเอาไปลงกับครื่องอืนๆ ซึ่งแน่นอนว่ามันไม่มี data bast ที่เราเคยสร้างไว้
แล้ว ย่างนี้ โปรแกรมที่เรา install ไปนั้นมันจะเก็บข้อมูลลงฐานข้อมูลอย่างไร ?
|
 |
 |
 |
 |
Date :
2013-04-09 15:15:49 |
By :
kyokohoho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาของผมนะ
ผมก็มีฐานข้อมูลในเครื่องใดเครื่องหนึ่งในเครือข่ายครับ
ส่วนโปรแกรมก็สามารถตั้งค่าให้เชื่อมต่อไปที่เบสไหนก็ได้
หมายความว่าพอลงเสร็จในครั้งแรก โปรแกรมก็หาเบสไม่เจอหรอก
ตอนใช้งานครั้งแรก ก็ตั้งค่าเบสก่อน หลังจากนั้นก็จะใช้ได้ตลอดไป
ยกเว้นเครื่องแม่จะโดนคาร์บอม 
ลืมบอกอีกนิดครับ
ของผมตอนไปติดตั้งให้ลูกค้า จะมี backup base เปล่าๆไป restore ให้
|
ประวัติการแก้ไข 2013-04-09 15:26:43
 |
 |
 |
 |
Date :
2013-04-09 15:21:31 |
By :
คนงานตัดอ้อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบ เครื่อง ใคร เครื่อง มัน ละ ครับ
เช่นตัวอย่าง A มาซื้อโปรแกรม A อยู่เชียงใหม่ B อยู่ ขอนแก่น อย่างงี้ครับ คนละเครือข่าย (ใช้เครื่องใครเรื่องมัน)
(เป็นโปรแกรมพวก จัดการข้อมูลผู้ป่วย โรงบาล A โรงบาล B ครับ ใช้ใครใช้มัน ไม่มีความเกียวข้องกันทางละเครือข่าย ฐานข้อมูลเก็บที่เครื่องใครเรื่องมัน win app )
โปรแกรมจะติดต่อฐานข้อมูล อย่าง ไร หรื่อ เราต้องไปสร้างฐานข้อมูลรอ ก่อน setup ทุกครื่องทุกครั้ง หรือครับ
|
ประวัติการแก้ไข 2013-04-09 15:32:31 2013-04-09 15:33:17 2013-04-09 15:34:50
 |
 |
 |
 |
Date :
2013-04-09 15:30:36 |
By :
kyokohoho |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฮ่วย จำเป็นไหมว่าต้องเป็น sql server 2008
ถ้าไม่จำเป็นก็ใช้ access หรือ เขียนเป็น xml ก็ยังได้
แค่ถ้าต้องใช้ก็ต้องทำตัว install ให้ install sql express ไปด้วย
ส่วนการสร้าง database ใช้โปรแกรมสร้างก็ได้ ง่ายๆ
สร้างได้ทั้ง database, table แม้กระทั้ง initial ข้อมูลลงไปเลยยังได้
|
 |
 |
 |
 |
Date :
2013-04-09 15:46:29 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ linq ส่วน data ก็โหลดจาก xml ซึ่ง add เป็น resource ไว้ใน project
database ถ้าไม่มี linq มันฉลาดพอที่จะสร้างให้เอง หรือถ้าไม่มั่นใจก็มีคำสั่ง recreate ได้
ส่วน table ต้องตรวจสอบก่อนว่ามีหรือไม่ ถ้าไม่มีก็ใช้ sql command สั่ง create table พร้อมโหลด
ข้อมูลจาก xml เอาเอง
ในตัวอย่างเป็นของ asp.net แต่หลักการใช้ linq ไม่ว่าจะเป็น web หรือ win เหมือนกัน
Intranet2012.designer.cs
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.261
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
public partial class Intranet2012DataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
#endregion
public Intranet2012DataContext() :
base(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Intranet2012"].ConnectionString, mappingSource)
{
OnCreated();
}
public Intranet2012DataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public Intranet2012DataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public Intranet2012DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public Intranet2012DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
/*--------------------------------------------------------------*/
public bool TableExist(string TableName)
{
string checkCommand = string.Format("If Exists (Select * From sys.tables Where name = '{0}') Select 'true' Else Select 'false'", TableName);
bool result = Convert.ToBoolean(this.ExecuteQuery<string>(checkCommand).SingleOrDefault());
return result;
}
public Table<TableRole> RoleTable
{
get { return GetTable<TableRole>(); }
}
}
#pragma warning restore 1591
Intranet2012Datebase.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Web.Security;
using System.Data;
using System.Reflection;
using System.IO;
/// <summary>
/// Summary description for Intranet2012Datebase
/// </summary>
public class Intranet2012Datebase
{
public Intranet2012Datebase()
{
//
// TODO: Add constructor logic here
//
}
public static void PreparingDataBase()
{
Intranet2012DataContext intranet2012 = new Intranet2012DataContext();
if (!intranet2012.DatabaseExists())
{
intranet2012.CreateDatabase();
}
if (!intranet2012.TableExist("RoleTable"))
{
TableRole roleTable = new TableRole();
roleTable.Create();
}
FillInitailData(intranet2012);
}
protected static void FillInitailData(Intranet2012DataContext intranet2012)
{
if ((from r in intranet2012.RoleTable select r).Count() == 0)
{
var Rt = from rt in XElement.Load(HttpContext.Current.Request.MapPath("~/InitialData/Role.xml")).Elements("Role")
select rt;
// Execute the query
foreach (var rTable in Rt)
{
TableRole role = new TableRole();
if (rTable.Element("TypeID") != null) role.TypeID = Convert.ToInt16(rTable.Element("TypeID").Value);
if (rTable.Element("RoleName") != null) role.RoleName = rTable.Element("RoleName").Value;
intranet2012.RoleTable.InsertOnSubmit(role);
intranet2012.SubmitChanges();
if (!Roles.RoleExists(role.ID.ToString("00")))
Roles.CreateRole(role.ID.ToString("00"));
}
}
}
}
TableRole.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq.Mapping;
using System.Text;
/// <summary>
/// Summary description for UserType
/// </summary>
[Table(Name = "RoleTable")]
public class TableRole
{
private int id;
private int typeId;
private string roleName;
public TableRole()
{
//
// TODO: Add constructor logic here
//
}
[Column(Storage = "id", DbType = "Int not null Identity", IsPrimaryKey = true, CanBeNull = false, AutoSync = AutoSync.Default, IsDbGenerated = true)]
public int ID
{
get { return id; }
}
[Column(Storage = "typeId", DbType = "Int")]
public int TypeID
{
get { return typeId; }
set { typeId = value; }
}
[Column(Storage = "roleName", DbType = "NVarChar(64)")]
public string RoleName
{
get { return roleName; }
set { roleName = value; }
}
public void Create()
{
Intranet2012DataContext Intranet2012 = new Intranet2012DataContext();
StringBuilder SbCreate = new StringBuilder();
SbCreate.AppendLine("Create Table [RoleTable]");
SbCreate.AppendLine("(");
SbCreate.AppendLine("[ID] int Identity(1,1) Primary Key Clustered,");
SbCreate.AppendLine("[TypeID] int,");
SbCreate.AppendLine("[RoleName] nvarchar(64),");
SbCreate.AppendLine(")");
Intranet2012.ExecuteCommand(SbCreate.ToString());
}
}
Role.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2012-05-09T18:22:07">
<Role>
<ID>1</ID>
<TypeID>1</TypeID>
<RoleName>ระบบจัดการผู้ใช้งาน</RoleName>
</Role>
<Role>
<ID>2</ID>
<TypeID>1</TypeID>
<RoleName>แสดงบันทึกการใช้งาน</RoleName>
</Role>
<Role>
<ID>3</ID>
<TypeID>2</TypeID>
<RoleName>ประชาสัมพันธ์</RoleName>
</Role>
<Role>
<ID>4</ID>
<TypeID>2</TypeID>
<RoleName>ข้อความวิ่ง</RoleName>
</Role>
<Role>
<ID>5</ID>
<TypeID>2</TypeID>
<RoleName>สไลด์ภาพส่วนหัว</RoleName>
</Role>
</dataroot>
|
 |
 |
 |
 |
Date :
2013-04-10 09:01:53 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|