| Author |
Topic |
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2011-10-17 : 20:04:33
|
| CLR Stored Procedure.NET 3.5Database set to External PermissionALTER DATABASE VC SET TRUSTWORTHY ONCLR EnabledProblem: Returns strCurrentTime and pathdir1 OK but will not return pathdir or pathdir2 when Exec dbo.clrsptest from within SQL Server Management Studio?Result:Current System DateTime is: 18/10/2011 10:12:23 AM C:\Program Files (x86)using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;using System.Collections.Generic;using System.ComponentModel;using System.Text;using System.Linq;using System.Net;using System.Security;using System.IO;public partial class StoredProcedures{ [Microsoft.SqlServer.Server.SqlProcedure] public static void CLRSPTest() { SqlPipe sp; sp = SqlContext.Pipe; String strCurrentTime = "Current System DateTime is: " + System.DateTime.Now.ToString(); String pathdir = Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); String pathdir2 = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); String pathdir1 = Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles); sp.Send(strCurrentTime); sp.Send(pathdir); sp.Send(pathdir1); sp.Send(pathdir2); }}C# project returns MyDocuments (pathdir) folder OK.using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace MyComputerTest{ public partial class Form1 : Form { public Form1() { InitializeComponent(); String pathdir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); String pathdir2 = System.Environment.SystemDirectory; int a = 0; } }} |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2011-10-18 : 00:03:04
|
| Thanks, any idea through sql server 2008 how to get the current Windows User MyDocuments path? C:\Users\sharlington for example.Also see;http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=166688 |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2011-10-18 : 00:34:23
|
| This is for reporting so I don't have a front end app. My only tools are SQL Server Management Studio, what ever sql code can be written (T-SQL or CLR) and BIDS for creating templates. I was so close with my previous post http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=166688. Just could not work out why the idiom returned differently from DOS CMD prompt and xp_cmdshell.I did get something working in the end but what a mess. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2011-10-18 : 23:30:41
|
| While this works under a c# project I could not get this to work under a sql server clr database project either.using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;using System.Collections.Generic;using System.ComponentModel;using System.Text;using System.Linq;using System.Net;using System.Security;using System.IO;using System.Security.Principal;using Microsoft.Win32;using System.Security.Permissions;using System.Collections;using System.Diagnostics;public partial class StoredProcedures{ [Microsoft.SqlServer.Server.SqlProcedure] public static void ReadRegKey() { SqlPipe sp; sp = SqlContext.Pipe; string InstallPath = (string)Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Personal", null); sp.Send(InstallPath); }} Procedure and error. It is probably failing security and returning null?Use [vc]Create Table #t (date nvarchar (255))Insert Into #tExec dbo.ReadRegKeyDrop Table #tMsg 6522, Level 16, State 1, Procedure ReadRegKey, Line 0A .NET Framework error occurred during execution of user-defined routine or aggregate "ReadRegKey": System.ArgumentNullException: Value cannot be null.Parameter name: messageSystem.ArgumentNullException: at Microsoft.SqlServer.Server.SqlPipe.Send(String message) at StoredProcedures.ReadRegKey() |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|