本文整理汇总了C#中SqlCeConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCeConnection.Open方法的具体用法?C# SqlCeConnection.Open怎么用?C# SqlCeConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlCeConnection
的用法示例。
在下文中一共展示了SqlCeConnection.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDB
/// <summary>
/// Create the initial database
/// </summary>
private void CreateDB()
{
var connection = new SqlCeConnection(this.path);
try
{
var eng = new SqlCeEngine(this.path);
var cleanup = new System.Threading.Tasks.Task(eng.Dispose);
eng.CreateDatabase();
cleanup.Start();
}
catch (Exception e)
{
EventLogging.WriteError(e);
}
connection.Open();
var usersDB =
new SqlCeCommand(
"CREATE TABLE Users_DB("
+ "UserID int IDENTITY (100,1) NOT NULL UNIQUE, "
+ "UserName nvarchar(128) NOT NULL UNIQUE, "
+ "PassHash nvarchar(128) NOT NULL, "
+ "Friends varbinary(5000), "
+ "PRIMARY KEY (UserID));",
connection);
usersDB.ExecuteNonQuery();
usersDB.Dispose();
connection.Dispose();
connection.Close();
}
示例2: MultiRSSqlCE
public void MultiRSSqlCE()
{
if (File.Exists("Test.sdf"))
File.Delete("Test.sdf");
var cnnStr = "Data Source = Test.sdf;";
var engine = new SqlCeEngine(cnnStr);
engine.CreateDatabase();
using (var cnn = new SqlCeConnection(cnnStr))
{
cnn.Open();
cnn.Execute("create table Posts (ID int, Title nvarchar(50), Body nvarchar(50), AuthorID int)");
cnn.Execute("create table Authors (ID int, Name nvarchar(50))");
cnn.Execute("insert Posts values (1,'title','body',1)");
cnn.Execute("insert Posts values(2,'title2','body2',null)");
cnn.Execute("insert Authors values(1,'sam')");
var data = cnn.Query<PostCE, AuthorCE, PostCE>(@"select * from Posts p left join Authors a on a.ID = p.AuthorID", (post, author) => { post.Author = author; return post; }).ToList();
var firstPost = data.First();
firstPost.Title.IsEqualTo("title");
firstPost.Author.Name.IsEqualTo("sam");
data[1].Author.IsNull();
cnn.Close();
}
}
示例3: LocalDatabase
public LocalDatabase(string FilePath)
: base()
{
try
{
string fileName = Path.Combine(FilePath, "caselist.sdf");
connectionString = string.Format("Data Source=\"{0}\"", fileName);
SqlCeEngine en = new SqlCeEngine(connectionString);
if (!File.Exists(fileName))
{
en.CreateDatabase();
}
m_connection = new SqlCeConnection();
m_connection.ConnectionString = connectionString;
if (m_connection.State == System.Data.ConnectionState.Closed)
{
try
{
m_connection.Open();
}
catch (SqlCeInvalidDatabaseFormatException)
{
en.Upgrade();
m_connection.Open();
}
}
SqlCeCommand SelectTableCommand = new SqlCeCommand();
SelectTableCommand.CommandText = QuerySelectRowString;
SelectTableCommand.Connection = m_connection;
m_adapter = new SqlCeDataAdapter((SqlCeCommand)SelectTableCommand);
// Create the DbCommandBuilder.
m_builder = new SqlCeCommandBuilder();
m_builder.DataAdapter = m_adapter;
m_adapter.SelectCommand = SelectTableCommand;
}
catch
{
throw;
}
}
示例4: button2_Click
private void button2_Click(object sender, EventArgs e)
{
DataConnectionDialog dcd = new DataConnectionDialog();
DataConnectionConfiguration dcs = new DataConnectionConfiguration(null);
dcs.LoadConfiguration(dcd);
if (DataConnectionDialog.Show(dcd) == DialogResult.OK)
{
textBox2.Text = dcd.ConnectionString;
connectionString = dcd.ConnectionString;
comboBox1.Enabled = true;
using (SqlCeConnection con = new SqlCeConnection(connectionString))
{
comboBox1.Items.Clear();
con.Open();
using (SqlCeCommand command = new SqlCeCommand("SELECT table_name FROM INFORMATION_SCHEMA.Tables", con))
{
SqlCeDataReader reader = command.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader.GetString(0));
}
}
}
//textBox1.Text = dcd.SelectedDataSource.DisplayName;
}
dcs.SaveConfiguration(dcd);
}
示例5: ctlrptActiveCall
public ctlrptActiveCall()
{
try
{
InitializeComponent();
ConnectionString = VMuktiAPI.VMuktiInfo.MainConnectionString;
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.ToString() + "rptActiveCall.sdf"))
{
System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory.ToString() + "rptActiveCall.sdf");
}
SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
clientEngine.CreateDatabase();
LocalSQLConn = new SqlCeConnection();
LocalSQLConn.ConnectionString = ClientConnectionString;
LocalSQLConn.Open();
fncActiveCallTable();
LocalSQLConn.Close();
objRefreshReport = new delRefreshReport(fncRefreshReport);
NetPeerClient npcActiveCall = new NetPeerClient();
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcJoinCall += new NetP2PBootStrapActiveCallReportDelegates.DelsvcJoinCall(ctlrptActiveCall_EntsvcJoinCall);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcGetCallInfo += new NetP2PBootStrapActiveCallReportDelegates.DelsvcGetCallInfo(ctlrptActiveCall_EntsvcGetCallInfo);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcActiveCalls += new NetP2PBootStrapActiveCallReportDelegates.DelsvcActiveCalls(ctlrptActiveCall_EntsvcActiveCalls);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcSetDuration += new NetP2PBootStrapActiveCallReportDelegates.DelsvcSetDuration(ctlrptActiveCall_EntsvcSetDuration);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcUnJoinCall += new NetP2PBootStrapActiveCallReportDelegates.DelsvcUnJoinCall(ctlrptActiveCall_EntsvcUnJoinCall);
channelNetTcpActiveCall = (INetP2PBootStrapReportChannel)npcActiveCall.OpenClient<INetP2PBootStrapReportChannel>("net.tcp://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + ":6000/NetP2PBootStrapActiveCallReport", "ActiveCallMesh", ref objActiveCall);
channelNetTcpActiveCall.svcJoinCall(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName);
}
catch (Exception ex)
{
VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "ctlrptActiveCall", "ctlrptActiveCall.xaml.cs");
}
}
示例6: conectaBD
public void conectaBD()
{
SqlCeConnection PathBD = new SqlCeConnection("Data Source=C:\\Facturacion\\Facturacion\\BaseDeDatos.sdf;Persist Security Info=False;");
//abre la conexion
try
{
da = new SqlCeDataAdapter("SELECT * FROM USUARIOS ORDER BY ID_USUARIO", PathBD);
// Crear los comandos de insertar, actualizar y eliminar
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
// Asignar los comandos al DataAdapter
// (se supone que lo hace automáticamente, pero...)
da.UpdateCommand = cb.GetUpdateCommand();
da.InsertCommand = cb.GetInsertCommand();
da.DeleteCommand = cb.GetDeleteCommand();
dt = new DataTable();
// Llenar la tabla con los datos indicados
da.Fill(dt);
PathBD.Open();
}
catch (Exception w)
{
MessageBox.Show(w.ToString());
return;
}
}
示例7: frmDetail_Load
private void frmDetail_Load(object sender, EventArgs e)
{
myConnection = default(SqlCeConnection);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
Adapter = default(SqlCeDataAdapter);
myConnection = new SqlCeConnection(storagePath.getDatabasePath());
myConnection.Open();
myCommand = myConnection.CreateCommand();
myCommand.CommandText = "SELECT [ID],[Job],[ItemId],[Qty],[Unit],[CheckedDateTime],[CheckedBy],[Checked] FROM ["
+ storagePath.getStoreTable() + "] WHERE ID ='"
+ bm + "' and Job='" + jb + "' and ItemId = '" + item + "' and Checked='true'";
myCommand.CommandType = CommandType.Text;
Adapter = new SqlCeDataAdapter(myCommand);
Adapter.Fill(ds);
Adapter.Dispose();
if (ds.Tables[0].Rows.Count > 0)
{
//isCheck = true;
this.txtItem.Text = ds.Tables[0].Rows[0]["ItemId"].ToString();
this.txtCheckedDateTime.Text = ds.Tables[0].Rows[0]["CheckedDateTime"].ToString();
this.txtCheckedBy.Text = ds.Tables[0].Rows[0]["CheckedBy"].ToString();
}
else
{
// isCheck = false;
}
myCommand.Dispose();
dt = null;
myConnection.Close();
}
示例8: Test
public override void Test()
{
string testString = ToTestString();
// Create a connection object
SqlCeConnection connection = new SqlCeConnection();
// Try to open it
try
{
connection.ConnectionString = ToFullString();
connection.Open();
}
catch (SqlCeException e)
{
// Customize the error message for upgrade required
if (e.Number == m_intDatabaseFileNeedsUpgrading)
{
throw new InvalidOperationException(Resources.SqlCeConnectionProperties_FileNeedsUpgrading);
}
throw;
}
finally
{
connection.Dispose();
}
}
示例9: SqlServerCeProcessor
public SqlServerCeProcessor(SqlCeConnection connection, IMigrationGenerator generator, IAnnouncer announcer, IMigrationProcessorOptions options)
: base(generator, announcer, options)
{
Connection = connection;
connection.Open();
BeginTransaction();
}
示例10: GetApplicationId
public static Guid GetApplicationId(string connectionString, string applicationName)
{
using (SqlCeConnection conn = new SqlCeConnection(connectionString))
{
using (SqlCeCommand cmd = new SqlCeCommand("SELECT ApplicationId FROM [aspnet_Applications] " +
"WHERE ApplicationName = @ApplicationName", conn))
{
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 256).Value = applicationName;
conn.Open();
var applicationId = cmd.ExecuteScalar();
if (applicationId == null)
{
cmd.Parameters.Clear();
cmd.CommandText = "INSERT INTO [aspnet_Applications] (ApplicationId, ApplicationName, LoweredApplicationName, Description) VALUES (@ApplicationId, @ApplicationName, @LoweredApplicationName, @Description)";
applicationId = Guid.NewGuid();
cmd.Parameters.Add("@ApplicationId", SqlDbType.UniqueIdentifier).Value = applicationId;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 256).Value = applicationName;
cmd.Parameters.Add("@LoweredApplicationName", SqlDbType.NVarChar, 256).Value = applicationName.ToLowerInvariant();
cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 256).Value = String.Empty;
cmd.ExecuteNonQuery();
}
return (Guid)applicationId;
}
}
}
示例11: Commit
public void Commit()
{
var connectionString = repository.GetConnectionString();
using (var conn = new SqlCeConnection(connectionString))
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
foreach (var command in commands)
{
try
{
SQLCeHelper.ResetParameterNullValue(command);
command.Transaction = trans;
command.Connection = conn;
command.ExecuteNonQuery();
}
catch (Exception e)
{
throw new KoobooException(e.Message + "SQL:" + command.CommandText, e);
}
}
trans.Commit();
}
}
//Execute post content events
foreach (var action in postActions)
{
action();
}
Clear();
}
示例12: GetDbList
internal List<Cmd> GetDbList()
{
List<Cmd> list = new List<Cmd>();
SqlCeConnection con = new SqlCeConnection(connectionString);
try
{
con.Open();
SqlCeDataAdapter adapter = new SqlCeDataAdapter(
"select * from cmd order by name", con);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, "Cmd");
DataTable table = dataSet.Tables["Cmd"];
foreach (DataRow row in table.Rows)
{
Cmd cmd = new Cmd();
cmd.name = (string)row["name"];
cmd.description = (string)row["description"];
cmd.path = (string)row["path"];
cmd.arg = (string)row["arg"];
list.Add(cmd);
}
}
finally
{
if (con != null)
{
con.Close();
}
}
return list;
}
示例13: InsertCmd
internal void InsertCmd(Cmd cmd)
{
SqlCeConnection con = new SqlCeConnection(connectionString);
try
{
con.Open();
//SqlCeDataAdapter adapter = new SqlCeDataAdapter(
// "insert into cmd (name, description, path, arg) values (" +
// "'" + cmd.name + "'," +
// "'" + cmd.description + "'," +
// "'" + cmd.path + "'," +
// "'" + cmd.arg + "'" +
// ")", con);
//SqlCeCommand sqlCmd = adapter.InsertCommand;
//int count = sqlCmd.ExecuteNonQuery();
SqlCeCommand sqlCmd = con.CreateCommand();
sqlCmd.CommandText = "insert into cmd (name, description, path, arg) values (" +
"'" + cmd.name + "'," +
"'" + cmd.description + "'," +
"'" + cmd.path + "'," +
"'" + cmd.arg + "'" +
")";
int count = sqlCmd.ExecuteNonQuery();
}
finally
{
if (con != null)
{
con.Close();
}
}
}
示例14: CreateUser
public static User CreateUser(string username, string password)
{
SqlCeConnection con = new SqlCeConnection(CONNECTION_STRING);
try
{
con.Open();
SqlCeCommand comm = new SqlCeCommand("INSERT INTO users (username, password, salt, dateCreated) VALUES (@username, @password, @salt, @createdDate)", con);
comm.Parameters.Add(new SqlCeParameter("@username", username));
comm.Parameters.Add(new SqlCeParameter("@password", password));
comm.Parameters.Add(new SqlCeParameter("@salt", String.Empty));
comm.Parameters.Add(new SqlCeParameter("@createdDate", DateTime.UtcNow));
int numberOfRows = comm.ExecuteNonQuery();
if (numberOfRows > 0)
{
return GetUser(username);
}
}
catch (Exception ex)
{
Debug.Print("CreateUser Exception: " + ex);
}
finally
{
if (con != null && con.State == ConnectionState.Open)
{
con.Close();
}
}
return null;
}
示例15: ApplicationState
private ApplicationState()
{
// read the application state from db
SqlCeConnection _dataConn = null;
try
{
_dataConn = new SqlCeConnection("Data Source=FlightPlannerDB.sdf;Persist Security Info=False;");
_dataConn.Open();
SqlCeCommand selectCmd = new SqlCeCommand();
selectCmd.Connection = _dataConn;
StringBuilder selectQuery = new StringBuilder();
selectQuery.Append("SELECT cruiseSpeed,cruiseFuelFlow,minFuel,speed,unit,utcOffset,locationFormat,deckHoldFuel,registeredClientName FROM ApplicationState");
selectCmd.CommandText = selectQuery.ToString();
SqlCeResultSet results = selectCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
if (results.HasRows)
{
results.ReadFirst();
cruiseSpeed = results.GetInt64(0);
cruiseFuelFlow = results.GetInt64(1);
minFuel = results.GetInt64(2);
speed = results.GetSqlString(3).ToString();
unit = results.GetSqlString(4).ToString();
utcOffset = results.GetSqlString(5).ToString();
locationFormat = results.GetSqlString(6).ToString();
deckHoldFuel = results.IsDBNull(7) ? 0 : results.GetInt64(7);
registeredClientName = results.IsDBNull(8) ? string.Empty : results.GetString(8);
}
}
finally
{
_dataConn.Close();
}
}