2013年2月28日 星期四

Apache+PHP5 使用Mysql遇到的問題

Window 7 重灌後, 重拾PHP的專案, 啟動時遇到的問題, 在 Phpinfo 內怎樣都看不到MySql載入, php.ini 也都沒有設定錯, 查看 Apache 的 error.log 出現如下

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\AppServ\\php5\\ext\\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0

原因不是別的, 只是少了 libmysql.dll ;

把libmysql.dll複製一份到C:\Windows\System32就好了.

PS: 請注意你的libMySql.dll 的 版本與 php 相同.

2013年2月21日 星期四

在Google Sites(協作) 使用 Goolge Driver(Google Docs)的資料夾文件

參考https://developers.google.com/apps-script/articles/embedding_docslist_in_sites的作法

在Site的管理界面, 新增一個Script

function showFolderInSite() {
var files = DocsList.getFolderById('Google資料夾ID').getFiles();
var page = SitesApp.getPageByUrl('要出現的協作網頁網址');
var attachments = page.getAttachments();

for (i in attachments) {
attachments[i].deleteAttachment();
}

for (i in files) {
page.addWebAttachment(files[i].getName(), '', files[i].getUrl());
}
}

 

1.替換程式內資料夾ID

 


2.替換程式內網頁的URL


image


 


整個結果大致如下


image


 


再回到協作去看就可以看到同步過來的檔案了, 但是如果Driver有再新增檔案, 必須再執行一次Script, 應該還有其它方法吧. 有空再研究.

2013年2月18日 星期一

MS-SQL 2008 msdb missing(遺失)

今天做了一件很蠢的事, 我竟然不認識msdb, 把 MSDBData.mdf 給永久刪除了.

結果重新開機再次進入SQL Server Management Studio時, 出現了

TITLE: Microsoft SQL Server Management Studio
------------------------------

Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

Database 'msdb' cannot be opened due to inaccessible files or insufficient memory or disk space.  See the SQL Server errorlog for details. (Microsoft SQL Server, Error: 945)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.4000&EvtSrc=MSSQLServer&EvtID=945&LinkId=20476

Google後,在 MSDN 找到解答, 關鍵字是  Rebuild System Databases,

重點是要找到安裝光碟(或重新下載download), 找到媒體目錄內的setup.exe . 用命令列重新產生.

提供我的指令供參考.

Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=SQLEXPRESS /SQLSYSADMINACCOUNTS=BUILTIN\Administrators  /SAPWD= StrongPassword /SQLCOLLATION=Chinese_Taiwan_Stroke_CI_AS

另外注意一點, 你的目錄 MSSQL\Binn\Templates 內有沒有範本檔, 它是用這裡的範本來產生的, 如果沒有, 也要重媒體檔(setup\sql_engine_core_inst_msi\Pfiles\SqlServr\MSSQL.X\MSSQL\Binn\Templates)再複製過來.

執行完成, 是沒有訊息的, 有訊息表示沒有成功, 要檢查你的參數, 檢查 C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Logs 下的 Summary.txt .

2013年1月10日 星期四

BaseHttpHandler

/// <summary>
/// An abstract base Http Handler for all your
/// <see cref="IHttpHandler"/> needs.
/// </summary>
/// <remarks>
/// <p>
/// For the most part, classes that inherit from this
/// class do not need to override <see cref="ProcessRequest"/>.
/// Instead implement the abstract methods and
/// properties and put the main business logic
/// in the <see cref="HandleRequest"/>.
/// </p>
/// <p>
/// HandleRequest should respond with a StatusCode of
/// 200 if everything goes well, otherwise use one of
/// the various "Respond" methods to generate an appropriate
/// response code. Or use the HttpStatusCode enumeration
/// if none of these apply.
/// </p>
/// </remarks>
public abstract class BaseHttpHandler : IHttpHandler
{
/// <summary>
/// Creates a new <see cref="BaseHttpHandler"/> instance.
/// </summary>
public BaseHttpHandler() {}

/// <summary>
/// Processs the incoming HTTP request.
/// </summary>
/// <param name="context">Context.</param>
public void ProcessRequest(HttpContext context)
{
SetResponseCachePolicy(context.Response.Cache);

if(!ValidateParameters(context))
{
RespondInternalError(context);
return;
}

if(RequiresAuthentication
&& !context.User.Identity.IsAuthenticated)
{
RespondForbidden(context);
return;
}

context.Response.ContentType = ContentMimeType;

HandleRequest(context);
}

/// <summary>
/// Indicates whether or not this handler can be
/// reused between successive requests.
/// </summary>
/// <remarks>
/// Return true if this handler does not maintain
/// any state (generally a good practice). Otherwise
/// returns false.
/// </remarks>
public bool IsReusable
{
get
{
return true;
}
}

/// <summary>
/// Handles the request. This is where you put your
/// business logic.
/// </summary>
/// <remarks>
/// <p>This method should result in a call to one
/// (or more) of the following methods:</p>
/// <p><code>context.Response.BinaryWrite();</code></p>
/// <p><code>context.Response.Write();</code></p>
/// <p><code>context.Response.WriteFile();</code></p>
/// <p>
/// <code>
/// someStream.Save(context.Response.OutputStream);
/// </code>
/// </p>
/// <p>etc...</p>
/// <p>
/// If you want a download box to show up with a
/// pre-populated filename, add this call here
/// (supplying a real filename).
/// </p>
/// <p>
/// </p>
/// <code>Response.AddHeader("Content-Disposition"
/// , "attachment; filename=\"" + Filename + "\"");</code>
/// </p>
/// </remarks>
/// <param name="context">Context.</param>
public abstract void HandleRequest(HttpContext context);

/// <summary>
/// Validates the parameters. Inheriting classes must
/// implement this and return true if the parameters are
/// valid, otherwise false.
/// </summary>
/// <param name="context">Context.</param>
/// <returns><c>true</c> if the parameters are valid,
/// otherwise <c>false</c></returns>
public abstract bool ValidateParameters(HttpContext context);

/// <summary>
/// Gets a value indicating whether this handler
/// requires users to be authenticated.
/// </summary>
/// <value>
/// <c>true</c> if authentication is required
/// otherwise, <c>false</c>.
/// </value>
public abstract bool RequiresAuthentication {get;}

/// <summary>
/// Gets the content MIME type.
/// </summary>
/// <value></value>
public abstract string ContentMimeType {get;}

/// <summary>
/// Sets the cache policy. Unless a handler overrides
/// this method, handlers will not allow a respons to be
/// cached.
/// </summary>
/// <param name="cache">Cache.</param>
public virtual void SetResponseCachePolicy
(HttpCachePolicy cache)
{
cache.SetCacheability(HttpCacheability.NoCache);
cache.SetNoStore();
cache.SetExpires(DateTime.MinValue);
}

/// <summary>
/// Helper method used to Respond to the request
/// that the file was not found.
/// </summary>
/// <param name="context">Context.</param>
protected void RespondFileNotFound(HttpContext context)
{
context.Response.StatusCode
= (int)HttpStatusCode.NotFound;
context.Response.End();
}

/// <summary>
/// Helper method used to Respond to the request
/// that an error occurred in processing the request.
/// </summary>
/// <param name="context">Context.</param>
protected void RespondInternalError(HttpContext context)
{
// It's really too bad that StatusCode property
// is not of type HttpStatusCode.
context.Response.StatusCode =
(int)HttpStatusCode.InternalServerError;
context.Response.End();
}

/// <summary>
/// Helper method used to Respond to the request
/// that the request in attempting to access a resource
/// that the user does not have access to.
/// </summary>
/// <param name="context">Context.</param>
protected void RespondForbidden(HttpContext context)
{
context.Response.StatusCode
= (int)HttpStatusCode.Forbidden;
context.Response.End();
}
}

2012年10月4日 星期四

好用的*.resources編輯器

跟同事找了半天的 Resources 編輯器, 正確名稱我不知道, 網路上都是 *DLL, *.Exe 或是 *.Resx *.rc

但是我要找到的是 *.Resources , 用途是什麼別問了, 我有一堆的 *.resources 要打開.
有試過直接改檔型 *.resources 改成 *.resx , 不能用, 還是binary.

找到Bill Sayles 在 codeproject 有分享一個專案, Resource Editor .NET , 還有原始碼, 狀況解除.

忘記我同事找的是哪一套了...

VisualStudio開發64位元系統MMC

遇到問題才會知道, 平常不用功, 看的書太少了.

在Win7上開發MMC 3.0 的專案, 按照這個網誌 寫了一支SnapIn 怎麼試都找到SnapIn可以增加...
最後想說該不會權限 or 64位元作業系統的問題吧?! 果然是
用了keyword : "visual studio mmc 64" 馬上找到

Debugging SnapIns in 64bit OS

64位元的MMC在
C:\Windows\SysWOW64\mmc.exe

你如果是用 命令列(CMD)去執行  C:\Windows\System32\MMC.EXE -32 也可以找到的你開發的SnapIn, 但是我要在VS2008內Deubg, 但是32的MMC.exe 掛(Attach)不上去, 所以還是用 C:\Windows\SysWOW64\mmc.exe -32的方式, 就能成功Debug了.


2012年9月17日 星期一

Create additional registry keys with DSL Tools Setup Projects



I was trying to solve the Custom Tool property issue with .actiw files in ActiveWriter, as suggested by Bogdan Pietroiu months ago, and spent a clear hour trying to figure how to inject my own registry keys into WiX setup project of DSL Tools. I modified the .vstemplate for .actiw files to include the following:

...
<CustomParameters>
  <CustomParameter Name="$itemproperties$" Value="CustomTool" />
  <CustomParameter Name="$CustomTool$" Value="ActiveWriterCodeGenerator" />
</CustomParameters>
...

and thought that the file, when added to the project, will have Custom Tool property already set. I was appearently wrong (documentation says it should work).

Bogdan's suggestion was to have a key named after the file extension under Generators\{Language}, and I manually confirmed that it works great. So, how to automate the process of adding this reg key through the setup? WiX Toolkit documentation shows the way, so I copied Registry.wxs to have my own key registered.
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>
  <Fragment Id="CustomToolFragment">
    <FeatureRef Id="DefaultFeature">
      <ComponentRef Id="_ActiveWriterCTReg" />
    </FeatureRef>
    <DirectoryRef Id="TARGETDIR">
      <Component Id="_ActiveWriterCTReg" Guid="{some GUID}">
        <Registry Root='HKLM' Key='Software\Microsoft\VisualStudio\8.0\Generators\{164b10b9-b200-11d0-8c61-00a0c91e29d5}\.actiw' Id='{some GUID}' Type='string'Value='ActiveWriterCodeGenerator' />
        <Registry Root='HKLM' Key='Software\Microsoft\VisualStudio\8.0\Generators\{fae04ec1-301f-11d3-bf4b-00c04f79efbc}\.actiw' Id='{some GUID}' Type='string'Value='ActiveWriterCodeGenerator' />
      </Component>
    </DirectoryRef>
  </Fragment>
</Wix>

<Registry> elements define the key to be added, as you may have guessed. Anyway, although I changed the build action on the .wxs and although it seems that Candle and Light picked up the file, the installer didn't add the registry key. So? Orca to the rescue. You should check Component and Registry tables in .msi file to check if your key slipped in, and Orca shows them quite detailed. In my case, though, it shows the absence of my additions.

Long story (not so) short, it seems that I should examine Registry.tt as the first step, but didn't. To include your ComponentRef in DefaultFeature, you should have your Fragment as FragmentRef in Main.wxs . So, you should add each of your custom fragment in the list defined incustomFragmentIds in InstallerDefinitions.dslsetup as shown below:

<installerDefinitionxmlns="http://schemas.microsoft.com/VisualStudio/2005/DslTools/InstallerDefinitionModel"
  ...
  customFragmentIds="CustomToolFragment">

I hope this info helps someone.