DBController开发后记--一些小的tips 推荐
2007-06-06 21:47
330 查看
一,调用 SQLDMO进行数据库备份的时候,容易如果备份的路径含有空格,就会失败,处理方式如下,这个是由于 SQLDMO本身不完备造成的
思想:调用API函数,把路径转为Dos模式
具体代码:
首先在类中声明此API
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName
(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath,
int shortPathLength
);
关于GetShortPathName函数的信息如下:
[in] Pointer to a null-terminated path string. The function retrieves the short form of this path.
lpszShortPath 目标数据字串,变短了
[out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath.
cchBuffer 目标数据字串的长度
[in] Size of the buffer pointed to by lpszShortPath, in TCHARs
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszShortPath, not including the terminating null character.
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.WIN32COM.v10.en/fileio/fs/getshortpathname.htm
其次调用此API的C#形式:
StringBuilder shortTargetFile = new StringBuilder(80);
int result = GetShortPathName(targetFile, shortTargetFile, shortTargetFile.Capacity);
objBackup.Files = shortTargetFile.ToString();
二:查找在Sql Server数据库中是否存在存储过程
代码如下:
SqlConnection sn = new SqlConnection("server=" + myServer + ";uid=" + myUser + ";pwd=" + myPassword + ";database=" + "");
sn.Open();
SqlCommand cmd = new SqlCommand(" SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[p_killspid]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1",sn);
SqlDataReader mySqlRdr = cmd.ExecuteReader();
while (mySqlRdr.Read())
{
//exist
mySqlRdr.Close();
sn.Dispose();
return true;
}
sn.Close();
把红色部分替换成你需要的存储过程名字即可
思想:调用API函数,把路径转为Dos模式
具体代码:
首先在类中声明此API
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName
(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath,
int shortPathLength
);
关于GetShortPathName函数的信息如下:
GetShortPathName
The GetShortPathName function retrieves the short path form of the specified path.DWORD GetShortPathName( LPCTSTR lpszLongPath, LPTSTR lpszShortPath, DWORD cchBuffer);
Parameters
lpszLongPath 源数据字串[in] Pointer to a null-terminated path string. The function retrieves the short form of this path.
lpszShortPath 目标数据字串,变短了
[out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath.
cchBuffer 目标数据字串的长度
[in] Size of the buffer pointed to by lpszShortPath, in TCHARs
Return Values
如果成功返回,返回值为目标字串的长度If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszShortPath, not including the terminating null character.
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.WIN32COM.v10.en/fileio/fs/getshortpathname.htm
其次调用此API的C#形式:
StringBuilder shortTargetFile = new StringBuilder(80);
int result = GetShortPathName(targetFile, shortTargetFile, shortTargetFile.Capacity);
objBackup.Files = shortTargetFile.ToString();
二:查找在Sql Server数据库中是否存在存储过程
代码如下:
SqlConnection sn = new SqlConnection("server=" + myServer + ";uid=" + myUser + ";pwd=" + myPassword + ";database=" + "");
sn.Open();
SqlCommand cmd = new SqlCommand(" SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[p_killspid]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1",sn);
SqlDataReader mySqlRdr = cmd.ExecuteReader();
while (mySqlRdr.Read())
{
//exist
mySqlRdr.Close();
sn.Dispose();
return true;
}
sn.Close();
把红色部分替换成你需要的存储过程名字即可
相关文章推荐
- 商用工程开发中的一些习惯 推荐
- sencha-touch开发的一些tips(tabPanel,提示框,store数据修改)
- 总结的一些PHP开发中的tips
- (转)总结的一些PHP开发中的tips
- 推荐Android开发中用到的一些优秀控件或框架
- android 小常识(包含一些界面开发的推荐颜色和自定义按钮~)
- 总结的一些PHP开发中的tips
- 推荐一些前端开发好的博客及文章、工具
- Android开发中一些你需要知道的图片相关知识和网站推荐分享
- 前端开发中的一些chrome插件推荐
- android 小常识(包含一些界面开发的推荐颜色和自定义按钮~) .
- 一些不错的开发工具和开发相关工具推荐
- 推荐一些国外嵌入式开发的网站
- playframework开发中的一些tips(打开新的html,删除提示)
- 总结一些tips(webapp开发相关)
- python开发的一些tips
- Animation cc H5的一些开发Tips
- iOS开发中的一些tips
- FW:推荐一些国外嵌入式开发的网站
- android 小常识(包含一些界面开发的推荐颜色和自定义按钮~)