Showing posts with label mdf. Show all posts
Showing posts with label mdf. Show all posts

Friday, March 30, 2012

How to script out my .mdf database I have in Visual Studio?

I'm using Visual Studio 2005 Standard. I have an .mdf database inside my Visual Studio "Server Explorer" under "Data Connections."

How do I script out this database, including the stored procedures in it? In other words, I want to export a SQL script that will create this database.

I'm very much a newbie when it comes to working with database management. I thought I created this .mdf inside my local install of SQL Server 2005 Express, but maybe I did it somehow inside Visual Studio in the Server Explorer. When I open up SQL Server Management Studio Express I don't see this database. I did locate the .mdf on my local C drive but I haven't been able to get Mgt Studio to open it.

Hi hapax_legomenon,

I use the Database Publishing Wizard to script my databases. You can select schema, data, schema and data, and be selective about which database objects you want and don't want. Microsoft wrote it, it's free, and on my list of "must-have" utilities. Here's the URL:

http://www.codeplex.com/sqlhost/Wiki/View.aspx?title=Database%20Publishing%20Wizard

Joe

|||

That's a great tool. Thanks!

how to script out .mdf file to .sql?

Hi

I am using Sqlserver2005. I need to convert .mdf to sql script. how can I do this?

Thanks

In your SQL management studio you right click on the database node and select "Tasks-->Generate Scripts..." This will start a wizard for you.

|||

Tasks->Generate Scripts will only generate a script to re-create the database. It will not create any table, let alone the table data.

Download the Microsoft SQL Server Database Publishing Wizard. This will script the entire database for you.

Jos

|||

Jos Branders:

Download the Microsoft SQL Server Database Publishing Wizard. This will script the entire database for you.

Hi Jos,

Through wizard it asks for database name. But I don't have any database created on SQLServer Management Studio. I just have .mdf and .ldf files.

How can I create sqlscript using those files?

Thanks

|||

You have to first import the database in sql server. Right click on databases and select Attach database.

|||

Thank you Richard. Its working.

sql

Friday, February 24, 2012

How to retrieve Date fields from an Access MDF on VS c++ Net 2005

I Apologize if this isn't the forum to ask this...
I have a MS Access (MDB) file with a table with 2 date fields, i want to read from a dialog on my app (on MS Visual .NET Studio 2005), here's the code I've been using do far:

Code Snippet

hr=theApp.m_cs.Open(theApp.m_ds);
if(SUCCEEDED(hr)) {

theApp.m_cs.StartTransaction();

theApp.m_cs.Commit();
CCommand< CDynamicAccessor > cmd;
CComBSTR query(_T("SELECT NumContrato, NumClie, FechaC, FechaCob, Inversion, NoCobrador, NoVendedor, Total, Plazo, Pagos FROM Contrato"));
CString string(query.m_str);
cmd.Open(theApp.m_cs,string);

hr = cmd.MoveFirst();

query=static_cast< BSTR >(cmd.GetValue(1));
CString csres(query.m_str);
this->m_numc=(int)*(query.m_str);
query=static_cast< BSTR >(cmd.GetValue(2));
m_numcte=(int)*(query.m_str);
query=static_cast< BSTR >(cmd.GetValue(3));
//m_fecc=(int)*(query.m_str);

MessageBox(csres);
theApp.m_cs.Close();
}



FechaC, FechaCob, are the two Dates I want to retrieve, but when I debug, it reads a 0 (zero) from the date fields, is there a limitation? can they be read? is there a special way to read them?
> thanks in advance!

--
Me!

I'm not experienced in templates, but it looks strange for me and you should check the type of the returned value.

If your field is of the type Date/Time then I'm not sure that simple casting is correct, since I would expect GetValue to return the pointer into the buffer with the actual data and I presume that the datatype there should be DBTYPE_DATE. Perhaps you need to create a specific accessor and explicitly request conversion to a string type.

|||Thanks A lot this is what i've done:

Code Snippet

DATE *d=(DATE*)(cmd.GetValue(3));

COleDateTime D(*d);

m_fec=D;

Sorry for the such a noob question you've been helpful! :)!