开发者

open external files or applications from sql command using sql server

i want to open notepad, word or excel files from sql server using some query. is this possible? or is it possbile using C#.NET winform application. ? also, i want sql to use dll files present it my hard drive. how do i do both these tasks? please help me out with the code as well.

EDIT:

i have a .net winform application which accessess sql server database & is used to insert data in the database.

i want t开发者_如何转开发hat when a user deletes a new record from a table in the database, & clicks the DELETE button on the Form, then the deleted data is exported to an excel file and the file is immediately opened.

is this possible?

for the export i would use bcp utility, but how to open the file ?


You can use XP_cmdshell to execute a process from within MS SQL server. http://msdn.microsoft.com/en-us/library/ms175046.aspx

I don't think you'll see the application actually open/run because MSSQL runs as a service and services have their own desktop that you can't see. You'll see the process running in task manager's processes tab however.

You can also excute other processes from a GUI application using the System.Diagnostics.Process class http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

also, i want sql to use dll files present it my hard drive

I don't understand this part. Please explain clearly what it is you're trying to do. What these dll files are and what they do and who created them. On the face of it I'd say no you can do this. But more importantly, I'd suggest you re-think the design of your application.


You can do it in .NET, using code like this:

VB.NET

 Dim ps As New ProcessStartInfo

    ps.UseShellExecute = True
    ps.FileName = fileName
    Process.Start(ps)

C#.NET

ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = filename;
Process.Start(ps);

I use it to open an Excel file I've just created. Should work just as well with other file types (assuming the proper program is installed).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜