SQL Server CE2.0 creates an encrypted database (source code)

Source: Internet
Author: User
Tags goto

1HRESULT hr =NoError;2Dbpropset dbpropset[2]; 3Dbprop dbprop[1];//Property Array to initialize the provider.4Dbprop sscedbprop[2];//Property Array for SSCE security properties5INT i =0;6IDBDataSourceAdmin *pidbdatasourceadmin =NULL;7IUnknown *piunknownsession =NULL;8IDBInitialize *pidbinitialize =NULL;9 //Create An instance of the OLE DB provider.Tenhr = CoCreateInstance (Clsid_sqlserverce_2_0,0, Clsctx_inproc_server, OneIid_idbinitialize, (void* *) &pidbinitialize); A if(FAILED (HR)) - { -Retailmsg (1, (TEXT ("1==cocreateinstance:%d/r/n"), GetLastError ()); the  GotoCleanexit; - } - //Initialize property structures. -VariantInit (&dbprop[0].vvalue); +  for(i =0; I <sizeof(Sscedbprop)/sizeof(sscedbprop[0]); i++) - { +VariantInit (&sscedbprop[i].vvalue); A } at //leo:to Create a new database, you must specify the DBPROP_INIT_DATASOURCE - //specify a name for the database. -dbprop[0].dwpropertyid =Dbprop_init_datasource; -dbprop[0].dwoptions =dbpropoptions_required; -dbprop[0].VVALUE.VT =VT_BSTR; -dbprop[0].vvalue.bstrval = SysAllocString (L"ENCRYPTED.SDF"); in if(NULL = = dbprop[0].vvalue.bstrval) - { tohr =e_outofmemory; +  GotoCleanexit; - } the //Specify the property for encryption. *sscedbprop[0].dwpropertyid =dbprop_ssce_encryptdatabase; $sscedbprop[0].dwoptions =dbpropoptions_required;Panax Notoginsengsscedbprop[0].VVALUE.VT =Vt_bool; -sscedbprop[0].vvalue.boolval =VARIANT_TRUE; the //specify the password. +sscedbprop[1].dwpropertyid =Dbprop_ssce_dbpassword; Asscedbprop[1].dwoptions =dbpropoptions_required; thesscedbprop[1].VVALUE.VT =VT_BSTR; +sscedbprop[1].vvalue.bstrval = SysAllocString (L"123456");//Password - if(NULL = = sscedbprop[1].vvalue.bstrval) $ { $hr =e_outofmemory; -  GotoCleanexit; - } the //Initialize the property sets. -dbpropset[0].guidpropertyset =Dbpropset_dbinit;Wuyidbpropset[0].rgproperties =Dbprop; thedbpropset[0].cproperties =sizeof(Dbprop)/sizeof(dbprop[0]); -dbpropset[1].guidpropertyset =Dbpropset_ssce_dbinit; Wudbpropset[1].rgproperties =Sscedbprop; -dbpropset[1].cproperties =sizeof(Sscedbprop)/sizeof(sscedbprop[0]); Abouthr = Pidbinitialize->queryinterface (Iid_idbdatasourceadmin, (void* *) &pidbdatasourceadmin); $ if(FAILED (HR)) - { -Retailmsg (1, (TEXT ("1==pidbinitialize->queryinterface:%d/r/n"), hr)); -  GotoCleanexit; A } + //Create and initialize the database. thehr = Pidbdatasourceadmin->createdatasource (sizeof(Dbpropset)/sizeof(dbpropset[0]), -Dbpropset, NULL, IID_IUnknown, &piunknownsession); $ if(FAILED (HR)) the { theRetailmsg (1, (TEXT ("1==pidbdatasourceadmin->createdatasource:%d/r/n"), hr)); the  GotoCleanexit; the } - //at this point, the new encrypted database is created. in Leanexit: theVariantClear (&dbprop[0].vvalue); theSysFreeString (dbprop[0].vvalue.bstrval); About  for(i =0; I <sizeof(Sscedbprop)/sizeof(sscedbprop[0]); i++) the { theVariantClear (&sscedbprop[i].vvalue); the } + //Do cleanup tasks here. - if(NULL! =pidbdatasourceadmin) the {BayiPidbdatasourceadmin->Release (); thePidbdatasourceadmin =NULL; the } - if(NULL! =pidbinitialize) - { thePidbinitialize->Release (); thePidbinitialize =NULL; the } the if(NULL! =piunknownsession) - { thePiunknownsession->Release (); thePiunknownsession =NULL; the }94 return;

SQL Server CE2.0 creates an encrypted database (source code)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.