This is a migrated thread and some comments may be shown as answers.

Save images in SQL Server - best practice

4 Answers 308 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Henric
Top achievements
Rank 1
Henric asked on 22 Jan 2009, 09:01 AM
I have been struggling with this for a few days now... I'm a .net newbie :-)
Namespaces, classes etc. is not one of my best areas...

I have implemented the RadEditor in my existing home-made CMS tool and it's now working as expected when editing content in my SQL server database. Now, I would like to be able to upload- and insert images stored in the database but I have some difficulties to accomplish that.

I have created the "Items" table and imported the sample data in my database.

Maybe it's a really stupid question, but how do I combine the two demo examples ("Save in database", http://demos.telerik.com/aspnet-ajax/Editor/Examples/SaveInDatabase/DefaultVB.aspx and "Db file browser Content provider" http://demos.telerik.com/aspnet-ajax/Editor/Examples/DBFileBrowserContentProvider/DefaultVB.aspx) into the same .aspx file?

Should the two "sample-code-behind" be merged somehow?

4 Answers, 1 is accepted

Sort by
0
Tervel
Telerik team
answered on 26 Jan 2009, 05:03 PM
Hello Henric,

I am not sure where the problem is.
You can certainly combine the two examples in one.

Please note that the DBFileBrowserContentProvider example codebehind consists of 2 classes.
Second class is the actual FileBrowserContentProvider implementation (which you got successfully running).

The first class is the actual page codebehind and is extremely simple - all it does is set the editor to point to the db content provider, e.g.

    public partial class DefaultCS : System.Web.UI.Page
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
            RadEditor1.ImageManager.ContentProviderTypeName = typeof(DBContentProvider).AssemblyQualifiedName;
        }
    }



So, to combine the two examples, all you need to do is use the database save example - and configure the editor there properly to point to this ContentProviderTypeName.

All the best,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Henric
Top achievements
Rank 1
answered on 09 Feb 2009, 01:33 PM
THanks for your reply!

I have advanced a bit now, it almost works to insert images from the database now, except for the following issues:

1. The path to the inserted image is wrong, Two "//" slashes is being added in front of the image path...

2. "Upload" and "create new folder" etc. doesn't work. It seems to be a problem with the SQL-statements in the dataserver-class. The parameterized queries fails with the following error: "The scalar variable must be declared..." As far as i know, this is related to what database im using (SQL server 2005). In the GetContent() function, i've changed it as follows:

 

Dim command As OleDbCommand = New OleDbCommand("SELECT Content FROM Items WHERE ItemID = @ItemID", Connection)

 

command.Parameters.Add(

New OleDbParameter("@ItemID", itemId))

Changed @ItemID to ? instead:

 

 

Dim command As OleDbCommand = New OleDbCommand("SELECT Content FROM Items WHERE ItemID = ?", Connection)

 

command.Parameters.Add(

New OleDbParameter("@ItemID", itemId))

Do I need to change this in the other functions as well? If so, why?
Is there any other solutions?

I'm using the following connectionstring:

 

<

 

connectionStrings>

 

  <

 

add name="ConnectionString" connectionString="Provider=SQLOLEDB;Data Source=mydatabase;Password=mypassword;User ID=myuser;Initial Catalog=mycatalog" providerName="System.Data.SqlClient"/>

 

</

 

connectionStrings>

 

 

 



 

0
Henric
Top achievements
Rank 1
answered on 09 Feb 2009, 03:27 PM

Since i've made som further progress, I must reply to myself:

1. The path to the inserted image is wrong, Two "//" slashes is being added in front of the image path...
This is solved by removing the "~/" in web.config's key="Telerik.WebControls.EditorExamples.ItemHandler.

About the second problem, "named parameters" are not allowed when using OleDb Data Providers. It worked when i changed to using SqlClient providers instead. OleDb uses positioned parameters, like question marks "?".

I still don't understand how the Telerik sample code could work, maybe it is related to their use of Access database...?

Now it seems to be only one small problem left, no new folder is created and no files are being uploaded, and no erros occur ;-)
I think i'll give the sql profiler a go!

I applogize for the ugly post before.

0
Lini
Telerik team
answered on 16 Feb 2009, 09:01 AM
Hi,

We are not sure about the OleDB provider/SqlClient provider difference - with SqlClient you should be able to use named query parameters as well (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx). Our demo is using an Access database (.mdb file, OleDB provider), which supports the named parameters (e.g. "@ItemID").

Perhaps you should try replacing all OleDb* related classes with the ones from the SqlClient namespace. For example:

OleDbCommand -> SqlCommand
OleDbParameter -> SqlParameter
...
In this case you will also need to change your connection string - for example:

<add name="ConnectionString" connectionString="Data Source=SERVER;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

Greetings,
Lini
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Editor
Asked by
Henric
Top achievements
Rank 1
Answers by
Tervel
Telerik team
Henric
Top achievements
Rank 1
Lini
Telerik team
Share this question
or