Posts

How to add a linked sql server using LINQ in C#? -

i'm trying replace hardcoded sql queries linq expressions. here's (simplified) code want replace: list<string> sqlcommands = new list<string> { @"exec sp_attach_single_file_db @dbname='localdb', @physname=n'c:\dbfile.mdf'", @"exec sp_addlinkedserver @server='notlocaldb'" }; sqlconnection conn = new sqlconnection(@"server=.\sqlexpress; integrated security=true"); conn.open(); foreach (string commandstring in sqlcommands) { var command = new sqlcommand(commandstring, conn); command.executenonquery(); } conn.close(); i've replaced sp_attach_single_file_db command linq statement: dbdatacontext localdb = new dbdatacontext(@"server=.\sqlexpress; database=localdb; integrated security=true"); localdb.createdatabase(); but can't find equivalent command sp_addlinkedserver . is there way can create linked server localdb using linq? var connstringbui...

vba - Excel Userform not initialising after first load -

i have workbook has multiple layers of userforms. when workbook opened user presented userform has 2 command buttons, 1 selects worksheet pivottable , slicers , second opens userform containing 8 command buttons, 7 of call further individual userforms , 8 close button. the issue have when select command button opens new userform, close second userform , reselect command button reopen second userform, second userform appears none of command buttons work nor close window (x). the code behind first command button follows: private sub cmd_manageabsence_click() splashscreen.hide load managementfunctions managementfunctions.show end sub the close , terminate code on second userform follows: private sub cmd_close_click() unload managementfunctions end sub private sub userform_terminate() sheets("front").activate splashscreen.show end sub i having same issues second layer of userforms, guess if first layer sorted can apply fix rest. thanks...

regex - Javascript Lookbehind with Global Search Overlapped -

there several (sometimes tricky) solutions lookbehind regexps in javascript. but, easiest way, if need zero width! behind expression global search, may overlap. e.g. using /(?<=[01])\d/g following: var = "--1--01001--1087---"; a.replace(/(?<=[01])\d/g, "#"); // should return "--1--0####--1##7---" if lookbehind supported or example: how can create \b expression works letters ( [a-za-z] ). (lookforward no question. js not support lookbehind). the look-behind through reversal approach seems easiest here. approach best short numeric patterns one. function revstr(str) { return str.split('').reverse().join(''); } var s = "--1--01001--1087---"; var rxp = /\d(?=[01])/g; var result = revstr(revstr(s).replace(rxp, "#")); document.write(result); logics: \d(?=[01]) reversed regex (?<=[01])\d we reverse input string revstr(s) function we reverse replacement result again...

android - Fragment Transaction Commit: State Loss in OnClick? -

i still dont seem state loss error when commiting fragment. have listview onclicklistener: public void onlistitemclick(listview l, view v, int position, long id) { switch (position) { case 0: fragmenttabactivity.addfragments(maintabhostactivity.gettabnames()[0], new openerlocationlistfragment(), true); break; } } and addfragments method: public void addfragments(string tabname, fragment fragment, boolean add) { if (add) { hmaptabs.get(tabname).add(fragment); } fragmentmanager manager = getsupportfragmentmanager(); fragmenttransaction ft = manager.begintransaction(); ft.replace(android.r.id.tabcontent, fragment); ft.commit(); } how can lose state in short time frame? can understand why happens in asynctasks should different here (other allowing state loss)? has suggestions?

multithreading - In Java, multiple threads want to manipulate one object, how to get one manipulate that and the others wait until the work is done? -

my problem little complicated: have concurrent map, threads want visit , update map, if 2 thread want fetch same entry of map, 1 should first map, update it, , other should wait until entry has been updated , fetch entry. original thought that: can use concurrent map, same key targeting map , use latch value. code like: private final concurrentmap<long, list<rowkeymap>> targetmap; private final concurrentmap<long, countdownlatch> helpermap; long keymillis; //key countdownlatch restorelatch = helpermap.get(keymillis); if (restorelatch != null) { try { restorelatch.await(); } catch (interruptedexception e) { thread.currentthread().interrupt(); throw new runtimeexception("interrupted trying " + keymillis); } } list<rowkeymap> restoredata = targetmap.get(keymillis); if (restoredata == null) { //find entry should restored, put latch helpermap , restore restorelatch = ne...

How do I create many matrices inside a loop statement with python? -

i want create example n matrices like: m1 = [[0,0],[0,0]] m2 = [[0,0],[0,0]] . . mn = [[0,0],[0,0]] i think work you res = [[[0 item3 in range(2)] item2 in range(2)] item1 in range(10)] print res output: [ [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]] ] basically 10(your n value) arrays 2x2 lists of zeros.

c - Prob with binary files using sockets -

this not total code. this working fine normal files text files, not working tar.gz , binary files transfer please me. and how send chunks of memory using sockets. server.c void main() { int sockfd, new_fd; // listen on sock_fd, new connection on new_fd struct sockaddr_in my_addr; // address information struct sockaddr_in their_addr; // connector's address information socklen_t sin_size; struct sigaction sa; int yes=1; char buf[16384]; char remotefile[maxdatasize]; if ((sockfd = socket(af_inet, sock_stream, 0)) == -1) { perror("socket"); exit(1); } if (setsockopt(sockfd, sol_socket, so_reuseaddr, &yes, sizeof(int)) == -1) { perror("setsockopt"); exit(1); } my_addr.sin_family = af_inet; // host byte order my_addr.sin_port = htons(myport); // short, network byte order my_addr.sin_addr.s_addr = inaddr_any; // automatically fill ip memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); printf("call binding...