Packaging Images with SQL Server Script - sql-server

i have a sql server db which needs to be deployed with an asp.net application. In a particular master table data is populated via a batch when installing the app. There are some images which must be saved in the db during installation. How do I package these images and how do I supply the path to these images ?

In SQL Server, they will end up as binary data. So you can script them out as a hexadecimal string, like this:
INSERT INTO myTable(ImageColumn)
VALUES (0x104321943324798543...)
That's the simplest way. There are plenty of tools that can do the scripting for you, the IDE that I wrote (which you can find here) included.

Related

Duplicate localDB under SQL Servers on my laptop

I've been running into an issue recently when I attempt any tutorials that involve using a SQL database, entity framework, dapper, etc.
When it comes time to publish a database, or utilize an ORM, I'm given duplicate options for the same localdb under SQL Servers. Furthermore, then I attempt to publish, the database doesn't show up under the localdb that I've chosen.
I'm wondering how I go about removing the other SQL Servers and just having the one available.
If you look at the image below, the Browse option gives me two of the same LocalDbs. Plus I also get a 3rd one under \ProjectModels. I'm wondering what's causing this and how it can be fixed since no matter which one I choose, the sql database I attempt to publish doesn't show up within any of them.
My advice is not to use this method to publish the database. (right click to delete)
Please refer to this official documentation.
File-based databases like SQLite or SQL Server Express are designed to store their data in easily transferable files that can be served with your application/site.
"Copy to Output Directory" Property of the database file to "Copy if newer". Just point the address to it.
If you are using a server-based database like SQL Server, MySQL, etc., you need to make sure that the target machine/environment has the same database server installed, and you need to write a deployment script to append the pre-populated data files to the server. This might be troublesome for you.
You can also refer to these links. 1,2,3

How to Handle Automation of Flat Files in SQL Server

Problem:
I receive multiple sets of flat files on a weekly basis that need t be imported my Database. The flat files I receive are not in a conventional format to import, so they need to be run through a script and be parsed in to a more SQL friendly format. These flat files are usually in JSON, TXT, XML, LOG, ect.
Current Solutions
Current I have a windows forms application and another GUI to transform the files and to bulkimport to SQL tables. However, I'm finding it unreliable to ask users to import data, and I would much rather automate the tasks.
More recently, I have been creating SSIS packages. This proves to much faster and useful since I can add script components. It allows me to manually parse whatever flat files I throw at it. My issue is finding a way to automate this. I have no control of the server where my database is hosted. So I'm unable to deploy the packages there to bring in the files. Currently, I'm just running the packages on my local machine manually to get the data in.
Needed Solution
I need a way for me to automate getting these flat files in. Originally I wanted to request and FTP server for the files to be dumped in. Then the files would be picked up by my packages and imported into the SQL Server DB. However, since I have no control of any of the local folders on that server, it seems to be impossible for me to automate this. Is there a better way for me to find a solution for this? Could I build something custom in C#, Python, Powershell, etc.? I'm very new to the scene and trying to find a solution for this problem has been a nightmare.

Embedded database on external drive

Have some application which uses SQL Server database on client server. Some time ago client requested to install application on external disk to be given someone else. My problem is somehow i have to attach database on external disk. Is it possible somehow to install sql server database on pendrive along with application? I heard something about sql compact. Can you update me on that topic?
I have not used SQL Compact but SQL Compact is suitable for in-proc, small, light-weight databases but has certain limitations as compared to SQL Express, no support for views, stored procedures, remote data access etc. You can find more at sql-express-v-localdb-v-sql-compact-edition
In a recent project, one of my clients had similar requirements and this is how achieved it with SQL Server Express.
As per my configuration I placed both the application and the database on the external disk. The database was placed in a subfolder named Database in the Bin folder. I declared my connection string as
Data Source=SERVER_NAME\SQLEXPRESS_INSTANCE;AttachDbFilename=DATABASE_FILE_NAME_WITH_FULL_PATH;Integrated Security=True;Connect Timeout=30;User Instance=True
As a quick solution SERVER_NAME\SQLEXPRESS_INSTANCE was configured and taken from App.Config but DATABASE_FILE_NAME_WITH_FULL_PATH was generated dynamically (external drive letters may change) using path constructs such as Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Database\ABC.MDF") etc. and inserted into the DataConnection string. So, whenever the application runs it searches for the ABC.MDF in Database subfolder of application executable path. You may need to tweak this approach as per your requirements such as Application.StartupPath / Application.ExecutablePath etc.
For more information and another example on AttachDbFilename check MSDN system.data.sqlclient.sqlconnectionstringbuilder.attachdbfilename

how to save large files - WAMP server, Database

I am creating a database on a WAMP server, running locally on my machine for now. I want to organize audio files, I understand I can use BLOB in the database but this is apparently very slow. I thought the best way would be to use a database with a reference to the location of the audio file. How do you achieve this using WAMP server? I have created the database, I need to add a folder of some onto the server. Also is there any other way of trying to get where I want?
Problem resolved by using folder on saved on the server and using webclient class (C#) to upload the file and SQL to alter the database which holds information on that file, including the location in the server.

How to use BCP on a hosted SQL Server/IIS environment? What is an alternative to BCP

I have a web application built in ASP and initially hosted on my own local server - Win 2008, IIS 7.0, SQL Server 2008.
I then bought a discountASP.Net hosting account for website + database.
The web application takes a file from a folder under the website root and bulk inserts into records in the database. Everything worked fine on the local development box.
When the database + website was moved to the DiscountASP.Net hosted account, the BULK INSERT would not worked and DiscountASP.Net told us that BULK INSERT is not allowed since the hosted database server is a shared server.
What is the work around for this scenario? They have indicated that we could use individual INSERTs.
Is there are better solutions out there? Has someone faced a similar problem and have some solution in place that we can re-use? (rather than reinventing the wheel).
Thanks for looking up my problem.
You'd have to use SQLBulkCopy from .net or send in XML to be parsed in SQL code
After some trial, I was able to get a solution myself. Here are the solution steps (Due to client confidentiality, I cannot share the code):
I read all the text from the file on the Web Server from the ASP code using the Scripting.FileSystemObject server object.
I am passing the entire text of the file as a variable to a stored procedure (SQL Server 2008). The datatype of the parameter has to be "adLongVarChar" Refer the data type table here (If the enum is not recognized, as was my case, I used the value 201 instead of the enum).
Wrote SQL code in stored procedure to parse the string into rows and then further parse each line into column values.
Hope the pseudo code of my solutions is helpful to someone.

Resources