Wednesday, May 23, 2012

data source configuration wizard issue Could not get column information for database object named

I'm using Visual Studio 2010 and connecting to MySQL database through MySqlODBC 5.1 driver. The page is a reporting page (I'm using crystal report and devexpresss reporting tool).



I have successfully tested the ODBC connection to my MYSQL database using Data source Configuration wizard, and after creating connectionString I can see my database objects , i.e. Tables , Stored procedures, but when I select any table , it do not expand to show me columns and when i click on finish it gives me data source configuration wizard error message,



<tyrepro..vendor>
Could not get column information for database object named 'tyrepro..vendor'



*vendor is table name here.



I tried connecting to system database and select table , but got same issue.





not-read-only DataGridView, but don't show input in datagridview after leaving, only show programmatical input

In my DataGridView users are able to input data. The DataGridView automatically changes its content when one of the properties of a correspondent list of objects changes with the help of events.



Now I want to give the DataGridView the following behavior: when the user inserts data, and then leaves the cell, the input should be validated. If the validation gives a positive result, the input is saved to an object. The datagridview should then show the input value in the correct format (eg. for a date).



I can make this work: the events between the list of objects and the datagridview can manage this.



The problem is: If the validation gives a negative result, the previous cell value should be restored.



I tried to use DataGridView.CellValidating event, but this doesn't work. What should I do?



SOLVED: I used e.Cancel. This doesn't really do what I thought it promissed. When I use DataGridView1.CancelEdit(), it works like I wanted.





gunicorn + zope error handling

we are trying to setup gunicorn + plone. It works well so far, but fails to handle errors (404, 500 etc) and throws 'Internal Server Error' while it should return plone's error page.



Example case of requesting a page that doesn't exist is pasted below. The question is how should gunicorn be setup so that errors are handled themselves by zope/plone, as other requests?



Cheers and regards



==> var/log/gunicorn-stdout---supervisor-JhaTfg.log <==
2012-05-24 01:41:16 [15137] [ERROR] Error handling request
Traceback (most recent call last):
File "/home/user/testing/eggs/gunicorn-0.14.3-py2.6.egg/gunicorn/workers/sync.py", line 100, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/user/testing/eggs/repoze.retry-1.0-py2.6.egg/repoze/retry/__init__.py", line 90, in __call__
app_iter = self.application(environ, replace_start_response)
File "/home/user/testing/eggs/repoze.tm2-1.0b2-py2.6.egg/repoze/tm/__init__.py", line 24, in __call__
result = self.application(environ, save_status_and_headers)
File "/home/user/testing/eggs/repoze.vhm-0.14-py2.6.egg/repoze/vhm/middleware.py", line 106, in __call__
return self.application(environ, start_response)
File "/home/user/testing/eggs/Zope2-2.13.13-py2.6.egg/ZPublisher/WSGIPublisher.py", line 255, in publish_module
response = _publish(request, 'Zope2')
File "/home/user/testing/eggs/Zope2-2.13.13-py2.6.egg/ZPublisher/WSGIPublisher.py", line 185, in publish
object = request.traverse(path, validated_hook=validated_hook)
File "/home/user/testing/eggs/Zope2-2.13.13-py2.6.egg/ZPublisher/BaseRequest.py", line 518, in traverse
return response.notFoundError(URL)
File "/home/user/testing/eggs/Zope2-2.13.13-py2.6.egg/ZPublisher/HTTPResponse.py", line 718, in notFoundError
"<p><b>Resource:</b> %s</p>" % escape(entry))
NotFound: <h2>Site Error</h2>
<p>An error was encountered while publishing this resource.
</p>




Using the login Details via Application

I have a CURL(in C++) to send my user and pass to remauth.php file so i think i do something wrong on remuth.php ( because i am basic in php and my program can not run because the auth not passed.)
I use login via Application.



my CURL:



bool Auth_PerformSessionLogin(const char* username, const char* password)
{
curl_global_init(CURL_GLOBAL_ALL);

CURL* curl = curl_easy_init();

if (curl)
{
char url[255];
_snprintf(url, sizeof(url), "http://%s/remauth.php", "SITEADDRESS.com");

char buf[8192] = {0};
char postBuf[8192];
_snprintf(postBuf, sizeof(postBuf), "%s&&%s", username, password);

curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, AuthDataReceived);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&buf);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "IW4M");
curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postBuf);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, -1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);

CURLcode code = curl_easy_perform(curl);
curl_easy_cleanup(curl);

curl_global_cleanup();

if (code == CURLE_OK)
{
return Auth_ParseResultBuffer(buf);

}
else
{
Auth_Error(va("Could not reach the SITEADDRESS.comt server. Error code from CURL: %x.", code));

}

return false;
}

curl_global_cleanup();
return false;
}


and my remauth.php:



<?php
ob_start();
$host=""; // Host name
$dbusername=""; // Mysql username
$dbpassword=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$dbusername", "$dbpassword") or die(mysql_error());
mysql_select_db("$db_name") or die(mysql_error());

// Define $username and $password
//$username=$username;
//$password=md5($_POST['password']);
//$password=$password;

$username=$_POST['username'];
$password=$_POST['password'];
//$post_item[]='action='.$_POST['submit'];


// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM $tbl_name WHERE username='$username'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
$row = mysql_fetch_assoc($result);
if (md5(md5($row['salt']).md5($password)) == $row['password']){
session_register("username");
session_register("password");
echo "#";
return true;
}
else {
echo "o";
return false;
}
}
else{
echo "o";
return false;
}
ob_end_flush();
?>


///////////////////////////////////





Exception when trying to parse JSON from a MySQL query

I'm having a problem parsing the JSON response from MySQL in Java.



try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://parkfinder.zxq.net/default.php");
httppost.setEntity(new UrlEncodedFormEntity(coordinatesToSend));
HttpResponse response = httpclient.execute(httppost);
Log.d("HTTP Client", "HTTP Request made");

HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,
"iso-8859-1"), 8);
sb = new StringBuilder();
sb.append(bufferedReader.readLine() + "\n");

String line = "0";
while ((line = bufferedReader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
bufferedReader.close();
result = sb.toString();
Log.d("RESULT", result);
JSONObject json_data = new JSONObject(result);
Log.d("JSON","Finished");
JSONArray nameArray = json_data.names();
JSONArray valArray = json_data.toJSONArray(nameArray);
for (int i = 0; i < nameArray.length(); i++) {
Log.d("NAMES", nameArray.getString(i));
}
for (int i = 0; i < nameArray.length(); i++) {
Log.d("NAMES", nameArray.getString(i));
}

} catch (Exception e) {
// TODO: handle exception
}


This is the MySQL Accessing and retreiving info, and parsing it afterwars.
the



Log.d("RESULT", result);


line posts the correct results:



2[{"longtitude":"32.32","latitude":"33.12"}]


however the



Log.d("JSON","Finished");


Never gets called,
so the problem seems to be on this line



JSONObject json_data = new JSONObject(result);


This while thing is taken from a tutorial which I saw many examples of it over the internet and on this site, some stated errors, but not this one.



Any help would be great!
Thanks



EDIT:
The printStackTrace() output:



0`5-14 21:38:18.639: WARN/System.err(665): org.json.JSONException: A JSONObject text must begin with '{' at character 1 of 2[{"longtitude":"32.32","latitude":"33.12"}]`


The php code:



<?php
$host = "localhost";
$user = "**MASKED**";
$password = "**MASKED**";
$database = "parkfinder_zxq_coordinates";
$connection = mysql_connect($host, $user, $password) or die("couldn't connect to server");
$db = mysql_select_db($database, $connection) or die("couldn't select database.");
//$request_parked = $_REQUEST['parked'];
$request_long = $_REQUEST['longtitude'];
$request_lat = $_REQUEST['latitude'];
//if ($request_parked == 'FIND') {
$q = mysql_query("SELECT * FROM Coordinates");
while ($e = mysql_fetch_assoc($q))
$output[] = $e;

print (json_encode($output));
//}

mysql_close();
?>




Read and Write Data to Excel without Installing Office

I am working on a WPF 4.0 application which uses the Microsoft Office Interop to read and write to Excel files. But I am facing a scenario where I need to read/write data from/to Excel files on systems that do not have Office installed.



This is somewhat a repeat of this question. The only reason I reposted this question because the earlier post was 3 years old and I just wanted to know if there is a better way available right now.



The requirement is that I need to write into and save the file as .xls/.xlsx formats and read from the same. I am supporting both the format using the Interop right now.




  • Buying a license is not an option.

  • Installing Excel is not an option.

  • Need to Support Read/Write from .xls/.xlsx formats.

  • Easy to Implement as I am a little behind schedule. Would not be able to give a lot of time on implementation.

  • Need a solution that is trustworthy and robust, meaning it should be something that you have used personally or have a good feedback about.

  • Would prefer a solution that can cater to both read/write and can support both .xls/.xlsx formats. If something like this doesn't exist, can use different solutions, but all the above points would apply to them individually.

  • Don't need suggestions, but more like guidance.



Please do not vote to close this question as duplicate as the other ones do not give a concrete solution. There are too many suggestions. I need a solution that you are confident about as this application goes into final build soon and if I do not get any robust solution to this, we might end up releasing as is.





android - one package replaces another

Android.
Eclipse.
Samsung S2
I have two apps I wrote.
Two different packages.
Both can be built and both run OK on the virtual and real device.
I want to leave both of them on the real device to play around with them for a couple of weeks.
Every time I install one, it replaces the other. Same happens whether I installing by running it from eclipse or by installing the APK straight on the phone.
The files have different names. The app names are different. I tried different package names. No luck.



What am I doing wrong?