Showing posts with label guys. Show all posts
Showing posts with label guys. Show all posts

Thursday, March 29, 2012

Exporting report to text files

Hi guys,

I have this problem with srs... That is when i launched a report it should automatically create a text file on my local machine... is this possible?

Thanks

Not sure what you mean here..

Have you looked at subscriptions with delivery to the file system?

|||

what i mean is that whenever i open a report it should auomatically export the the report into .txt file format without going through the export button.

Does SRS has that kind of feature or i need to create a separate assembly for it?

thanks

|||

I think you would have to do some custom programming. Have you looked at the ssrs web service methods available?

sql

Sunday, March 25, 2012

Exporting Data from SDF Database to CSV file

Hi guys,

Would any of you be able to provide some guide on how am I going to export the selected data (multiple rows and columns) into Excel or CSV file?

Or at least export into Text file, which I can later on save the file name as .CSV, so it become a CSV file after saving.

Thanks.

Regards,

Jenson

In which context is the data "selected". You can always enumerate your data and use the System.IO namespace to create the CSV file in code?|||

Hi Erik,

Yes Erik, that's what I intend to do, do you have any guide for me to follow, or any sample codes to refer to? I need to refer to them and write my own one, as I don't really think what I wanted to do is the same, I just need to structure and check how they do it, and what are the various ways to achieve the same thing.

Thanks.

Regards,

Jenson

|||

Hope this sample is what you are looking for:

Code Snippet

using System;

using System.Collections.Generic;

using System.Text;

using System.Data.SqlServerCe;

namespace ExportSDF

{

class Program

{

static void Main(string[] args)

{

SqlCeConnection conn = null;

SqlCeCommand cmd = null;

SqlCeDataReader rdr = null;

try

{

// Based on this sample: http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlcedatareader.aspx

// Open the connection and create a SQL command

//

conn = new SqlCeConnection(@."Data Source = C:\Program Files\Microsoft SQL Server Compact Edition\v3.1\SDK\Samples\Northwind.sdf;max database size=256");

conn.Open();

cmd = new SqlCeCommand("SELECT * FROM Customers", conn);

rdr = cmd.ExecuteReader();

System.IO.TextWriter stm = new System.IO.StreamWriter(new System.IO.FileStream(@."C:\customers.csv", System.IO.FileMode.Create), Encoding.Default);

// Iterate through the results

//

while (rdr.Read())

{

// Write all fields except the last one...

for (int i = 0; i < rdr.FieldCount-2; i++)

{

if (rdr[i] != null)

{

stm.Write(rdr[i].ToString());

stm.Write(";");

}

else

{

stm.Write(";");

}

}

if (rdr[rdr.FieldCount-1] != null)

{

stm.Write(rdr[0].ToString());

}

stm.Write(System.Environment.NewLine);

}

// Always dispose data readers and commands as soon as practicable

//

stm.Close();

rdr.Close();

cmd.Dispose();

}

finally

{

// Close the connection when no longer needed

//

conn.Close();

}

}

}

}

Happy coding!

|||Hi Erik,

Thanks for the great reply and sorry for the late reply. The reason behind is I have finished the workaround for this requirements and it's working just fine. By looking at your code, I find that this code is even easier to understand!

I will try it out later as I'm currently busy with other stuff. Thanks for the great codes, Erik! Wink

Have marked your answer as answer =)

Wednesday, March 21, 2012

Exporting a database

Hey guys another dumb question for you :)

How would I export the database on my computer to a file that I can stick on CD/floppy to use on another computer? Also what file format should I export it as?
Thanks for you help guys!

My final project is almost done and all I have left to do is tweak the SQL ERD a bit and impliment it into Visual Basic (thats gonna be fun figureing that out)

Thanks in advance!Ever heard of database backups !!!

Or for that sake detaching, attatching databases.

Look up the Holy Book (SQL Server Books online) for these thingssql

Wednesday, February 15, 2012

Export script data from sql server - suggestions for this case

Hello Guys,
I would like to export my database into a file in order to be used in
another server that I do not know? So, I would to be able to exprot
all the table structure, stored procedures and data (insert into).
How can I do it?
InaPerhaps you just need a database backup.
Ben Nevarez, MCDBA, OCP
Database Administrator
"ina" wrote:
> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>|||Ben
She wanted as I understood her only table's structure without any data
So , he may want to use SQLDMO objects to script out or Generate Script
Option in the EM
Sub ScriptDB(strLogin As String, strPwd As String, _
strDataBase As String, StrFilePath As String)
Dim sql As Object
Dim db As Object
Dim objTrigger As Object
Dim intOptions As Long
Dim genObj
Set sql = CreateObject("SQLDMO.SQLServer")
Set db = CreateObject("SQLDMO.Database")
Set objTrigger = CreateObject("SQLDMO.Trigger")
Const sDrops As Integer = 1
Const sIncludeHeaders As Long = 131072
Const sDefault As Integer = 4
Const sAppendToFile As Integer = 256
Const sBindings As Integer = 128
' Set scripting options. Because you need to specify multiple behaviors
' for the ScriptType argument, you use "Or" to combine these.
intOptions = sDrops Or sIncludeHeaders Or _
sDefault Or sAppendToFile Or sBindings
' Connect to local server
sql.Connect "(local)", strLogin, strPwd
Set db = sql.Databases(strDataBase, "dbo")
' Script User Defined Data Types
For Each genObj In db.UserDefinedDatatypes
genObj.Script intOptions, StrFilePath
Next
' Script Tables and Triggers, ignoring system
' tables and system generated triggers
For Each genObj In db.Tables
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
For Each objTrigger In genObj.Triggers
If objTrigger.SystemObject = False Then
objTrigger.Script intOptions, StrFilePath
End If
Next
End If
Next
' Script Rules
For Each genObj In db.Rules
genObj.Script intOptions, StrFilePath
Next
' Script Defaults
For Each genObj In db.Defaults
genObj.Script intOptions, StrFilePath
Next
' Script Sprocs, ignoring system sprocs
For Each genObj In db.StoredProcedures
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
End If
Next
' Script Views, ignoring system views and informational schemas
For Each genObj In db.Views
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
End If
Next
MsgBox "Finished generating SQL scripts."
End Sub
Save the module as MyModule.
Call ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
"Ben Nevarez" <bnevarez@.sjm.com> wrote in message
news:03E4FC21-234C-42DF-BF2D-649922C22CE0@.microsoft.com...
> Perhaps you just need a database backup.
> Ben Nevarez, MCDBA, OCP
> Database Administrator
>
> "ina" wrote:
>> Hello Guys,
>> I would like to export my database into a file in order to be used in
>> another server that I do not know? So, I would to be able to exprot
>> all the table structure, stored procedures and data (insert into).
>> How can I do it?
>> Ina
>>|||thanks but I would like to data too (copy the backup only is a
solution). But this script is very cool. Thanks|||Use www.sqlscripter.com to generate the data scripts for tables.
"ina" wrote:
> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>|||Thank you thomas. I will have a look on this tools.
Ina
Thomas wrote:
> Use www.sqlscripter.com to generate the data scripts for tables.
> "ina" wrote:
> > Hello Guys,
> >
> > I would like to export my database into a file in order to be used in
> > another server that I do not know? So, I would to be able to exprot
> > all the table structure, stored procedures and data (insert into).
> >
> > How can I do it?
> >
> > Ina
> >
> >

Export script data from sql server - suggestions for this case

Hello Guys,
I would like to export my database into a file in order to be used in
another server that I do not know? So, I would to be able to exprot
all the table structure, stored procedures and data (insert into).
How can I do it?
InaPerhaps you just need a database backup.
Ben Nevarez, MCDBA, OCP
Database Administrator
"ina" wrote:

> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>|||Ben
She wanted as I understood her only table's structure without any data
So , he may want to use SQLDMO objects to script out or Generate Script
Option in the EM
Sub ScriptDB(strLogin As String, strPwd As String, _
strDataBase As String, StrFilePath As String)
Dim sql As Object
Dim db As Object
Dim objTrigger As Object
Dim intOptions As Long
Dim genObj
Set sql = CreateObject("SQLDMO.SQLServer")
Set db = CreateObject("SQLDMO.Database")
Set objTrigger = CreateObject("SQLDMO.Trigger")
Const sDrops As Integer = 1
Const sIncludeHeaders As Long = 131072
Const sDefault As Integer = 4
Const sAppendToFile As Integer = 256
Const sBindings As Integer = 128
' Set scripting options. Because you need to specify multiple behaviors
' for the ScriptType argument, you use "Or" to combine these.
intOptions = sDrops Or sIncludeHeaders Or _
sDefault Or sAppendToFile Or sBindings
' Connect to local server
sql.Connect "(local)", strLogin, strPwd
Set db = sql.Databases(strDataBase, "dbo")
' Script User Defined Data Types
For Each genObj In db.UserDefinedDatatypes
genObj.Script intOptions, StrFilePath
Next
' Script Tables and Triggers, ignoring system
' tables and system generated triggers
For Each genObj In db.Tables
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
For Each objTrigger In genObj.Triggers
If objTrigger.SystemObject = False Then
objTrigger.Script intOptions, StrFilePath
End If
Next
End If
Next
' Script Rules
For Each genObj In db.Rules
genObj.Script intOptions, StrFilePath
Next
' Script Defaults
For Each genObj In db.Defaults
genObj.Script intOptions, StrFilePath
Next
' Script Sprocs, ignoring system sprocs
For Each genObj In db.StoredProcedures
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
End If
Next
' Script Views, ignoring system views and informational schemas
For Each genObj In db.Views
If genObj.SystemObject = False Then
genObj.Script intOptions, StrFilePath
End If
Next
MsgBox "Finished generating SQL scripts."
End Sub
Save the module as MyModule.
Call ScriptDB("UserName","Password","DatabaseName","C:\MyResults.SQL")
"Ben Nevarez" <bnevarez@.sjm.com> wrote in message
news:03E4FC21-234C-42DF-BF2D-649922C22CE0@.microsoft.com...[vbcol=seagreen]
> Perhaps you just need a database backup.
> Ben Nevarez, MCDBA, OCP
> Database Administrator
>
> "ina" wrote:
>|||Use www.sqlscripter.com to generate the data scripts for tables.
"ina" wrote:

> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>|||Use www.sqlscripter.com to generate the data scripts for tables.
"ina" wrote:

> Hello Guys,
> I would like to export my database into a file in order to be used in
> another server that I do not know? So, I would to be able to exprot
> all the table structure, stored procedures and data (insert into).
> How can I do it?
> Ina
>