Quantcast
Channel: .NET Framework inside SQL Server forum
Viewing all 780 articles
Browse latest View live

I/O operations in remote sql server file system

$
0
0
Hi. I'm facing a problem. I'm developing a web application in ASP.Net MVC 4 to bring web features to an already made desktop application, developed by other developer team. Both applications are connected to the same database. What i need to do is use part of the logic from the desktop app to send some data from one server (A) to another (B), which has both desktop and web applications as well. The DB has a stored procedure than export a file with the data that need to be sent to B. This is my idea so far to accomplish this.

- I execute the stored procedure and export the data to the file. This SP is transparent to me, was created by the other developer team and I don't know the format of this file and niether the data that store. Since this file is created from sql server, exist in the file system of the sql server that is not the same server where the web application is hosted.
- Then I take the file and send it to B through WCF.
- In B when the file is received is copied to the sql server file system.
- Finally I execute in the DB of B other stored procedure that imports the data from the file. This stored procedure also was created by the other team.

My problem is how to get the file from sql server file system to send it through WCF. Then how can I copy the file to B's sql server file system to import the data.

The file can be very large, over 4GB. My first idea was to use SQL SERVER FILESTREAM to once the file is created insert it in the DB and in that way can be access from the web app. I don't like this approach. When insert the file a duplicate of the file is created in the file system. Also to read the file in chuncks the web app need to be connected to the DB with integrated security and this does not work for me.

I forget to mention this, but I would like to read/write the file from/into the filesystem trhough SQL SERVER. Not use share folders or ftp servers and http servers from where I can request the file. I don't know if this is possible.
A friend of mine mentioned that creating a SQL SERVER DATABASE PROJECT in Visual Studio you can perform I/O operations in the SQL SERVER file system and read the file. I have not digged into this at all.

The applications are connected to two possible versions of SQL SERVER, 2012 or 2008.
Sorry for my English, my mother tongue is Spanish.
Waiting for suggestion. Thank you in advanced.

Azure DB User defined assembly support

$
0
0

I get this when trying to port an existing DB to Azure DB

Assembly 'xxxxx' cannot be loaded because Azure SQL Database does not support user-defined assemblies. Contact Azure Technical Support if you have questions.

Is this something that's going to be supported in the (near) future or something that can be enabled per subscription?

Thanks

Janardhan

Issue with CLR Procs

$
0
0

Hello All

We have a CLR procedure for converting names into meaningful names. This procedure actually calls a third party DLL. Names are input to this DLL and correct names are spitted out and later the tables are getting updated. Multiple users are using this CLR procedure and it is being called from UI.

No errors being logged at system level. When component will not work, tables are being updated with some default value. What would be the best solution to track the issue?


Request for SCOM reports already been requested.

best regards,

Siddarth

Load Json File using script component - 2014 sql server

$
0
0

Hi,

Please help me load the Json File into SQL server by parsing using .net

{
     "firstName": "John",
     "lastName": "Smith",
     "age": 25,
     "address":
     {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": "10021"
     },
     "phoneNumber":
     [
         {
           "type": "home",
           "number": "212 555-1234"
         },
         {
           "type": "fax",
           "number": "646 555-4567"
         }
     ]
 }

Thanks

CLR Runtime error framework 3.5 - System.Security.HostProtectionException

$
0
0

Hi all,

I´ve created a CLR Runtime dll following the steps of this post - https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b732a134-33ba-4880-838d-33fb93887d12/decript-data-on-field-level-that-was-encrypted-on-an-oracle-system?forum=transactsql

It was created for SQL Server 2012 and it works perfectly.

The problem is that the client database is SQL Server 2008 and a new project had to be created for due to the framework 3.5.

So a new dll was created and when I call it on SQL Server 2008 I´m having the following error message.

Msg 6522, Level 16, State 2, Line 1

A .NET Framework error occurred during execution of user-defined routine or aggregate "DecryptDataDecimal":

System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.

The protected resources (only available with full trust) were: All

The demanded resources were: MayLeakOnAbort

System.Security.HostProtectionException:

   en UserDefinedFunctions.Decrypt_AES(Byte[] cypherText, Byte[] Key, Byte[] IV)

   en UserDefinedFunctions.DecryptDataDecimal(String EncryptedData)

Any idea?

Thanks in advance

Can a CLR SQLFunction use a SqlUserDefinedType (table) as an input parameter?

$
0
0

Hi,

I have been unable to find a definitive answer if a sqlfunction can\cannot use a sqlUserDefinedType in the same class. The type is a table struct. It wont compile as the script generated results in the user type being removed with 'unsupported'. I may be missing the obvious. Any guidance appreciated.

public partial class UserDefinedFunctions
{

    [Serializable()]
    [SqlUserDefinedType(Format.UserDefined)]
    public struct ProductData : INullable
    {
        private Int32 id;
        private Int32 productID;
        private Int32 productVersionID;

.etc

.


    [SqlFunction(FillRowMethodName = "OrderTaxCalculationRow", TableDefinition = @" 
                                                                                   [TaxValue] Money NULL,
                                                                                   [Success] BIT,
                                                                                   [Message] nvarchar(1000)",
    DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)]
    public static IEnumerable mfnPTGetOrderTaxCalculation(SqlInt32 orderID, SqlInt32 orderItemID,
        SqlInt32 documentID, SqlBoolean isInvoiceRequest, SqlBoolean commitTaxTransaction, SqlBoolean returnXml,
        SqlInt32 billToRoleID,
        SqlInt32 billToAddressID,
        SqlInt32 shipToAddressID,
        ProductData productData,
        SqlInt32 shipToRoleID)



pass parameter in clr

$
0
0

Hi, I am using SQL Server 2014 and working on writing a clr function which would accept the table name as input instead of dbTable.Name. Please help me rewrite this.

foreach (Table dbTable in DB.Tables)
            {
string pattern = 'Dim_LookupTable_'

                Match match = Regex.Match(dbTable.Name, pattern, RegexOptions.IgnoreCase); //pass table name as parameter instead of dbTable.Name

                if (match.Success)
                {
                    Console.WriteLine(dbTable.Name);
                }
            }

Thank you in advance.


SQLEnthusiast

CLR SQLTrigger and events for query

$
0
0

Hi.

Would be possible to use something like SQLTriggers (in c#) for catch query events?

Sqltriggers allows INSERT, UPDATE & DELETE events. If possible, how could I know when a table is queried? My need is to execute custom code when this occurs.

Thank you very much



operation has failed (reason: version, culture or public key mismatch) System.Web.dll CREATE ASSEMBLY

$
0
0

I loaded the Reliability Rollup for .NET last night and it seems to have broken my CLR function.

I tried to recompile the DLL on my Windows 10 machine and then load it into my server but it started throwing a new error that it could not reference System.Web and asked me to load it into the database.

I added the following line into my deployment script:

CREATE ASSEMBLY [System.Web] from 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.dll' WITH PERMISSION_SET = UNSAFE;

But this is just throwing the following errors:

Warning: The Microsoft .NET Framework assembly 'system.web, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a, processorarchitecture=x86.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.
Warning: The Microsoft .NET Framework assembly 'system.drawing, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a, processorarchitecture=msil.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.
Warning: The Microsoft .NET Framework assembly 'system.enterpriseservices, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a, processorarchitecture=x86.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.
Warning: The Microsoft .NET Framework assembly 'system.runtime.remoting, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089, processorarchitecture=msil.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.
Msg 10300, Level 16, State 2, Line 1
Assembly 'System.Web' references assembly 'system.web, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: version, culture or public key mismatch). Please load the referenced assembly into the current database and retry your request.

I have noticed that the Digital Signature of System.Web.dll is different between my Windows 10 machine and my Windows Server 2012 R2.  The server has a new certificate on it with an August Date and my Windows 10 machine has a June date for its certificate. 

Do I need to recompile this DLL on a Windows Server 2012 R2 machine that has the same signature as my production SQL machine or is there some way to update .NET on my Windows 10 machine to have the same digital signature as the server?  I have all the latest patches and updates but do not see anything about the Reliability Rollup for Windows 10.

How to Pass value in Table Valued Parameter of Stored procedure

$
0
0

Hello,

I have a Stored Procedure which contains a table value parameter. table valued parameter contains three columns. I want to pass a datatable from my C# project . This datatable contains 10 columns and is there any way to map column of datatable to Table valued parameter columns ? 

However there is one solutions to create new datatable and drop all extra columns and pass it to table valued parameter but i don't want to do extra process.?


Prem Shah

Assembly from VB class Library... Starting

$
0
0

Hi, I wrote a class library in vb.net(VS2015).  Basically a set of functions to determine dates. I want to be able to use that library in SQL Sever. I am using SQL Server 2014/2016.

I think I've found bits and parts of how to do but I must be missing something.  I've not tired it yet, but have just started looking up information.

Is this doable?  What is it going to take?  Where is a good place to get started on reading about this?

c# program as a .net clr stored procedure

$
0
0
Hi, I am using Visual Studio 2015 & SQL Server 2014. I have the below C# program for which I have to pass the Table object name and the program generates the Create Table script. Now I am working on writing this as a SQL CLR Stored Procedure. Could you please give me an idea or direction to accomplish this.

public class CSHProgram
    {
        static void Main()
        {
            Server dbservername = new Server(@"(local)");
            string tablename = "";

            try
            {
                dbservername.ConnectionContext.LoginSecure = true;
                savetbldeftofile(dbservername, tablename);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (dbservername.ConnectionContext.IsOpen)
                    dbservername.ConnectionContext.Disconnect();
                Console.ReadKey();
            }
        }

        public static void savetbldeftofile(Server dbservername, string tablename)
        {
            StringBuilder sb = new StringBuilder();

            string tblName = @"\b" + tablename + "\b";

            foreach (Database DBServer in dbservername.Databases)
            {
                Match db = Regex.Match(DBServer.Name, "UserTestDB", RegexOptions.IgnoreCase);
                if (db.Success)
                {
                    foreach (Table dbTbl in DBServer.Tables)
                    {
                        Match tabl = Regex.Match(dbTbl.Name, tblName, RegexOptions.IgnoreCase);
                        if (tabl.Success)
                        {
                            ScriptingOptions soptions = new ScriptingOptions();
                            soptions.ClusteredIndexes = true;
                            soptions.Default = true;
                            soptions.DriAll = true;
                            soptions.Indexes = true;
                            soptions.IncludeHeaders = true;
                            soptions.AppendToFile = true;

                            StringCollection SCollection = dbTbl.Script(soptions);
                            foreach (string str in SCollection)
                            {
                                sb.Append(str);
                                sb.Append(Environment.NewLine);
                            }
                        }

                        StreamWriter sw = File.CreateText(@"c:\temp\" + tablename + ".sql");
                        sw.Write(sb.ToString());
                        sw.Close();
                    }
                }
            }
        }
    }

Thank you.

SQLEnthusiast

Compatibility of SQL Server 2012 with .Net Framework 4.6.1

$
0
0

Hi,

I am looking for compatibility of SQL Server 2012 with .Net Framework 4.6.1.

Does SQL server 2012 work fine with .Net Framework 4.6.1 or do I need to have only 4.0?

All of our servers need to be upgraded to .Net Framework 4.6.1 on mandatory basis and wanted to check whether SQL server 2012 is supported with framework 4.6.1 or not

Already I have explored msdn link for "Hardware and Software Requirements for Installing SQL Server 2012" but didn't get much clarity on the query. Looking for the proofs(links) that say it is compatible.

Your help is much appreciated.

Thank you,


Store Procedure issue

$
0
0

I have table with these values

PId	PhaseID	KIP	Target
1	11	119	10
1	11	120	20

When i going to insert 1 more record with this 2 record which store in a temp table it will  inserted only 2 record but i want 

output will be the 1st 2 record should updated and 3rd record will insert into that table.

Passing parameter to  StroreProcedure

declare @p7 dbo.AMT_Programe_KPI_Type (TempTable)
insert into @p7 values(119,N'10',N'0')
insert into @p7 values(120,N'20',N'0')
insert into @p7 values(121,N'30',N'0')


SQL Server Management Studio

$
0
0

I've installed SQL Server Management Studio 2016 but when I go to create a table it shows this error message . I'm using Visual stdio 2015. So what should I do now ?

""This backend version is not supported to design database diagrams or tables. (MS Visual Database Tools)""


Thank you.


install ms sql 2016

$
0
0

I need to install ms sql 2016 in windows 7 ultimate(64-bit)

I am going to develop project in C#.net 2015 community edition.

Thanks in advance

server 2012 iis Server Error in Application. The required permissions cannot be obtained.

$
0
0

Hello,

I am getting this error when I try to open the web site I installed on the server. What could be the problem? I'm glad you helped me.

My system;
Server sql 2012
IIS version 8.5


Server Error in '/' Application.

The required permissions can not be obtained.

Description: The current web request unhandled exception occurred during the execution. Please check the stack trace to find out more about the error and where it originated in the code. 

Exception Details: system.security.policy.policyexceptio: Required permissions can not be retrieved. 

Source Error: 
Geçerli web isteği yürütülürken işlenmeyen bir özel durum üretildi. Özel durumun kaynağı ve konumuna ilişkin bilgiler aşağıdaki özel durum yığını izlemesi kullanılarak belirlenebilir.

Stack Tracking: 
[PolicyException: Gerekli izinler alınamıyor.]
   System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7613891
   System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57

[FileLoadException: 'OpenNETCF.Desktop.Communication, Version=2.9.2244.24857, Culture=neutral, PublicKeyToken=null' dosyasını veya derlemesini ya da bağımlılıklarından birini yükleyemedi. Gereken en az izin istekleri verilemedi. (HRESULT özel durum döndürdü: 0x80131417)]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: 'OpenNETCF.Desktop.Communication, Version=2.9.2244.24857, Culture=neutral, PublicKeyToken=null' dosyasını veya derlemesini ya da bağımlılıklarından birini yükleyemedi. Gereken en az izin istekleri verilemedi. (HRESULT özel durum döndürdü: 0x80131417)]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +163
   System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +53
   System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +175
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +86
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +261
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +101
   System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +83
   System.Web.UI.PageParser.GetCompiledPageInstance(VirtualPath virtualPath, String inputFile, HttpContext context) +224
   System.Web.UI.PageParser.GetCompiledPageInstance(String virtualPath, String inputFile, HttpContext context) +121
   System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +736
   System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) +50
   System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +77

[InvalidOperationException: İstek işlenemiyor.]
   System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +285
   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +183

[InvalidOperationException: İstek işlenemedi.]
   System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +354
   System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212
   System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +307
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


Version Information:  Microsoft .NET Framework Version: 2.0.50727.8000; ASP.NET Version: 2.0.50727.8001


Handling exceptions from stored procedure using Raiserror

$
0
0
I thought it would be very easy to handle the errors thrown from SQL Server stored procedures.
Here is my sample stored procedure:
USE [mydb1]
GO

/****** Object:  StoredProcedure [dbo].[uspTest]    Script Date: 10/25/2009 00:51:47 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[uspTest]
AS
BEGIN
    BEGIN TRY
    --Do something that might cause an error such as SELECT 1/0
     select 1/0
    END TRY
BEGIN CATCH
    ---EXEC dbo.uspRethrowError
    RAISERROR ( 'ERROR occurred',16,1)
END CATCH
end;
GO

Here is

 my VB.NET code

 

        Try
            cn.Open()
            cmd.Connection = cn
            cmd.CommandText = "uspTest"
            cmd.CommandType = CommandType.StoredProcedure
            rdr = cmd.ExecuteReader()

        Catch ex As SqlException
            logger.Error("SQL Exception : " & ex.ToString)
       
        Finally
            cn.Close()

If I execute the stored procedure from MS SSMS, I see the error on the console. But when I execute from the vb.net code it does not work and the error could not be trapped. The code skips the Catch Block. Not sure why? I have searched all possible documentation on NET and could not figure out. Can any one help, the sooner the better. Thanks

How to share a LocalDB 2016 instance programmatically

$
0
0

I am invoking the SqlLocalDB.exe utility as a process from a Visual Studio .NET application to create and start a LocalDB instance.  That all works fine; however, when I try to share it, I get an error saying this requires an administrator.  Since the user is the administrator, I assume this requires an elevated command.  I've researched this online and the solutions either require embedding an administrator account and password (which is not feasible since this is a distributed app), or setting a 'runas' verb, which appears to do nothing.

I need this process to be transparent to the user (at worst, a UAC prompt).  How can this be done?


Steve Jensen

Disable manual editing of data in Microsoft SQL Server

$
0
0

I am using Microsoft SQL Server. As you know, edit the data in the database either manually by the original environment using SQL Server user sa or any user of other authorized and also through programming environment that connect to SQL Server to edit the data. Is there a way to disable this editing of data in the SQL Server environment so there is no person in the database manually does not change?

No users even through mssql unable to make changes in the original data. For example, to manually stock the number to another number that this event would not have realized how to change.

can SINGLE_USER help?
Can wizard sql manager for remote did not open ?
Who does not have access to sql server console? And changes only through a interface software or Command Line in master database server operating system?

I think that best way is "database only is edited by sa when connect directly to server and use command for edit database on shell environment and nobody cannot remotely edit it, i means dont connect console "ssms" remotely."


Viewing all 780 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>