How do you store a picture in an image column?

Here is a sample code for storing image to sql server : SqlConnection conn = new SqlConnection(connectionString); try { int imageLength = uploadInput.PostedFile.ContentLength; byte[] picbyte = new byte[imageLength]; uploadInput.PostedFile.InputStream.Read (picbyte, 0, imageLength); SqlCommand command = new SqlCommand(“INSERT INTO ImageTable (ImageFile) VALUES (@Image)”, conn); command.Parameters.Add(“@Image”, SqlDbType.Image); command.Parameters[0].Value = picbyte; conn.Open(); command.ExecuteNonQuery(); conn.Close(); } finally { if … Read more

SQL Server: How to tell if a database is a system database?

Just dived into Microsoft.SqlServer.Management.Smo.Database object (which is provided by Microsoft itself!) They simply do this using following statement: CAST(case when in (‘master’,’model’,’msdb’,’tempdb’) then 1 else dtb.is_distributor end AS bit) AS [IsSystemObject] In short: if a database is named master, model, msdb or tempdb, it IS a system db; it is also a system db, … Read more

SQL Server: How to permission schemas?

I fear that either your description or your conception of Ownership Chaining is unclear, so let me start with that: “Ownership Chaining” simply refers to that fact that when executing a Stored Procedure (or View) on SQL Server, the currently executing batch temporarily acquires the rights/permissions of the sProc’s Owner (or the sProc’s schema’s Owner) … Read more

Problem with Renaming a Column in SQL Server

/*Initial Table*/ CREATE TABLE AllocationDetails ( Conversion_Fee_Per_Share FLOAT ) /*Faulty Rename*/ EXEC sp_rename ‘dbo.AllocationDetails.[Conversion_Fee_Per_Share]’, ‘[Conversion_Fee]’, ‘COLUMN’ /*Fixed Rename*/ EXEC sp_rename ‘dbo.AllocationDetails.[[Conversion_Fee]]]’, ‘Conversion_Fee’, ‘COLUMN’ DROP TABLE AllocationDetails The column name to use in the second sp_rename call is that returned by SELECT QUOTENAME(‘[Conversion_Fee_Per_Share]’). Alternatively and more straight forwardly one can use EXEC sp_rename ‘dbo.AllocationDetails.”[Conversion_Fee]”‘, ‘Conversion_Fee’, ‘COLUMN’ … Read more