Copying A Single Database Table From VWDE To SQL Server Management Express

Apr 9, 2007

Hello,
As the heading states, I'd like to copy a database table from VWDE over to SQL SME, where it'll replace its namesake. I've tried the 'attach' method but was denied due to server permissions. Is there another way of doing this, or will I have to delete the database and then run a script to reinstate (annoyingly convoluted)? This would be so much easier if the host supported SQL 2005 Express.  
 Thanks in advance

 

View 2 Replies


ADVERTISEMENT

Failed To Generate A User Instance Of SQL Server Using Sql Server Express And Vwde. Why?

Jan 15, 2007

I've set up a website on another computer using sql server express and visual web developer express, and it works as expected. However halfway through the development i've had to move to another computer. I installed visual web developer express + sql server express, and copied the project files across, but now when I attempt to run it I get the error:Failed to generate a user instance of SQL Server due to a
failure in starting the process for the user instance. The connection
will be closed. I've tried reinstalling the software and it doesn't help. Any idea why this is happening, and what I can do to fix it?thanks 

View 3 Replies View Related

Problem Copying Database With Microsoft SQl Server Management Studio

Aug 16, 2007

I am trying to copy a database from the server on my web host(crystaltech) to my new local install of MS SQL Server 2005 Enterprise (trial version).

I go to Tasks>Copy Database which opens the wizard. When I get to the select database screen I get this error:

Server user 'username' is not a valid user in database '123foo'

(123foo is the first database of all those on the server)

I need have it look only at my database which I have permissions for to copy it. How do I do this?

I tried copying the tables the other way(import data) but it dropped all my identities and primary keys which is a pain to recreate. Is there a way to copy tables from one server to another without losing primary keys and identity fields?

Thanks for any help!

View 3 Replies View Related

Copying SQL Server Express Database

Jun 5, 2006

Help!

I have a customer who I have set up a SQL Server Express database for. The database was running fine, but I copied it over to my pc over the weekend to update some data. I have copied the data backwards and forwards plenty of times, but this time when I came to copy it back and reattach it on the customers' server I get the following message:

TITLE: Microsoft SQL Server Management Studio Express
------------------------------

Attach database failed for Server 'SBSSERVERBKUPEXEC'. (Microsoft.SqlServer.Express.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)

------------------------------

Could not find row in sysindexes for database ID 6, object ID 1, index ID 1. Run DBCC CHECKTABLE on sysindexes.
Could not open new database 'ACServe'. CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 602)


This is REALLY urgent.

Help me please

Gabby

View 1 Replies View Related

SQL Server Management Studio Express, Database Explorer In Visual Web Developer Express...which To Use???

Apr 16, 2007

When I downloaded/started using Visual Web Developer I was under the impression that I needed to install SQL Server Management Studio Express in order to create/manage databases, and to provide the engine to access the data.
 Since then I have found tutorials and have successfully created/used databases solely from within Visual Web Developer. I'm assuming that Visual Web Developer includes a database engine, much like the webserver that is included. (This is an awesome thing).
 When I tried to upload my web application with database to my production server, the database would not work, it started working after I installed SQL Server Management Studio Express on the server.
 Is it my understanding that you need SQL Server Management Studio Express if you do not have Visual Web Developer Express installed in order to provide the data access engine?
Also, I am unable to "attach" my Visual Web Developer Express created database to SQL Server Management Studio Express. Are there any posts that provide more information about this topic?
 
The only reason I'm asking is that I have extra whitespace on the end of my text fields, and I thought ANSI_PADDING was turned on. I do not see the option in Visual Web Developer Express, but have found it in SQL Server Management Studio Express.

View 14 Replies View Related

Import Existing Database Into SQL SERVER EXPRESS Management Studio Express

Feb 18, 2008



Hi,

I am a newbie so i apologies beforehand for any mistakes i make on this forum.
Anyway, i created an asp.net website using the MS Visual Web developer tool. This has a couple of SQL SERVER databases within it.
I then latervinstalled the SQL SERVER management studio express in order to manage the SQL SERVER DBs that i had as part of my website but they do not appear within the management studio db list.
As this is the express version, is there anyway of importing the existing SQL SERVER dbs that i have to the management studio so i can manage them from there?

Regards,

Shuja.

View 5 Replies View Related

Why Can't I See My Web Developer Express Database From SQL Server Management Studio Express?

Apr 30, 2006

Hi, I'm completely new to SQL Server and ASP.NET, so please bear with me on my learning curve! I've installed Visual Web Developer Express and SQL Server Express (on the same PC). I then used Web Developer Express to successfully create a new database with a couple of tables in it. So far so good. I then installed SQL Server Management Studio Express on the same PC and tried to connect to my new database. The connection to the SQL Server instance appears to work OK (using Windows Authentication) but I can't see the database I previously created. All I can see are the System Databases. Does anyone know what the solution might be?

View 4 Replies View Related

Northwind Database In SQL Server Management Studio Express Is Lost Or Used/processed By VB 2005 Express:How To Locate/return It

Dec 3, 2007

Hi all,

In the last one and half years, I used the Northwind Database in SQL Server Management Studio Express (SSMSE) to learn the programming of SqlConnections, Data sources, Database Exploere, ADO.NET 2.0, etc. via VB 2005 Express.

The Northwind Database in my SSMSE got lost very often, but I was not aware of it. How can I know where the Northwind Database is used or processed by my VB 2005 Express projects that were the examples of some tutorial books or my trial projects? How can I release the Northwind Database back to my SSMSE from the VB 2005 Express projects? Please help and advise.

Thanks in advance,
Scott Chang

View 2 Replies View Related

Copying Rows From Multiple Tables To A Single Table

Sep 20, 2007



Hi,

I have 3 tables with the follwing schema
Table <Category>
{

UniqueID,
LastDate DateTime
}


Assume the follwing tables with data following the above schema

Table Cat1
{

1, D1
2, D2
3, D3
}
Table Cat2
{

2, D4
3,D5
4, D6
}
Table Cat3
{

1, D7
3,D8
5,D9
}

I have a Master and the schema is as follows
Table master
{

UniqueId,
Cat1 DateTime, -- This is same as the Table name
Cat2 DateTime, -- This is same as the Table name
Cat3 DateTime -- This is same as the Table name
}

After inserting the data from all these 3 tables, I want the my master table to look like this
Table Master
{

UniqueId cat1 cat2 Cat3
------------ --------- ------- -----------
1 D1 NULL D7
2 D2 D4 NULL
3 D3 D5 D8
4 NULL D6 NULL
5 NULL NULL D9
}


Please remember the column names will be same as that of table names

can any one pelase let me know the query t o acheive this

Thanks for your quick response
~Mohan Babu

View 8 Replies View Related

How To Use Xcopy && User Instance To Copy 3 Dbo Tables From The Database Of SQL Server Management Studio Express To The App_Data Folder Of Website Of VWD Express Project?

Jan 6, 2007

Hi all,
I have read/studied (i) Working with Databases in Visual Web Developer 2005 Express in http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/vwd.aspx, (ii) Xcopy Deployment (SQL Server Express) in http://msdn2.microsoft.com/en-us/library/ms165716.aspx, (iii) User Instances for Non-Administrators in http://msdn2.microsoft.com/en-us/library/ms143684.aspx, and (iv) Embedding SQL Server Server Express in Applications in http://msdn2.microsoft.com/en-us/library/ms165660.aspx.  I do not understand the concepts and procedures to do Xcopy and User Instances for non-administrators completely-I do not know how to connect to databases and create database diagrams or schemas using the Database Explorer.  I have a stand-alone Windows XP Pro PC. I have created a ChemDatabase with 3 dbo tables in the SQL Server Management Studio of my SQL Server Express and a website of my VWD Express application with an App_Data folder.  I am not able to proceed to use Xcopy and user instance to bring the 3 dbo tables of ChemDatabase to my App_Data folder. Please help and give me some detailed procedures/instructions to bring the 3 dbo tables of ChemDatabase (or ChemDatabase itself) from the SQL Server Management Studio Express to the App_Data folder of the website of my VWD Express project? 
Thanks in advance,
Scott Chang 
 

View 3 Replies View Related

Error When Getting Data From The Database. VWDE/SQL/Asp.Net/C#

Jun 18, 2007

 I get the error:
Index out of range exception was unhandled by user code.
At the line:
Label4.Text += reader["RelativeLN"].ToString();

The two lines above it:
Label4.Text += reader["Relation"].ToString() + ": ";
Label4.Text += reader["RelativeFN"].ToString();

will read just fine if I comment out that third line. I don't
understand why this could be happening. There is data in the db for the
RelativeLN column and it has the same data type as the previous two
columns.

private void getRelatives()
{
//Define database connection
SqlConnection conn = new SqlConnection(
"Server=localhost\SqlExpress;Database=MyDB;" + "Integrated Security=True");
//Create command
SqlCommand comm = new SqlCommand("SELECT Relation, RelativeFN FROM
RelativeTable WHERE RelativeTable.UserID IN (SELECT UserID FROM UsrTbl
WHERE UserName = @usrnmeLbl)", conn);
comm.Parameters.AddWithValue("@usrnmeLbl", usrNmeLbl.Text);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
Label4.Text += reader["Relation"].ToString() + ": ";
Label4.Text += reader["RelativeFN"].ToString();
Label4.Text += reader["RelativeLN"].ToString();
}
}

I'm hoping someone can provide me some info on what could possibly be going wrong.
Thank you so much in advance.

View 2 Replies View Related

SQL Server Express Database.mdf - Remote Management

May 15, 2006

Hi,
I have installed an ASP.NET 2.0 application which uses a SQL Server Express database file on a client's network.  I am able to connect to my client's network remotely over the internet.  I would like to know if there's a way - and if so, how - to manage the Database file remotely.
I have VWD Express, SQL Server Manager Studio Express and a trial version of SQL Server 2005 on my development machine.
Thanks very much.
Regards
Gary

View 3 Replies View Related

Can Never Access Database Table From Code After Copying To Another SQL Server...

Nov 29, 2007

I am not sure I understand the problem I am causing, but I am a beginner!

Here's the situation: I have a table located on MS SQL server database number 1. Said table, which we'll call WIDGET_PRICES, is accessed regularly by my existing source code and has no problems.

At some point, I decide to move operations to MS SQL database number 2 and do a very simple database copy of WIDGET_PRICES from database 1 to database 2 using the Microsoft SQL Server Management Studio.

The end result, inevitably, is that my source code can no longer access the very same table as it is located on the new database server. The code hasn't changed, it's still trying to access WIDGET_PRICES as always. And, from what I see on my screen through Management Studio, WIDGET_PRICES appears just fine.

An example error is the one I just got:



Microsoft OLE DB Provider for SQL Server error '80040e37'

Invalid object name 'YB_ITEMS'.

/yardbark/tampabay/header.asp, line 27




The only clue is that while my transferred tables often look named like "database1.WIDGET_PRICES on database 1, they wind up looking like database2.WIDGET_PRICES on dabase 2.




I include a little more detail and screenshots of the tables in questions at this web page.




Dave

View 3 Replies View Related

Cannot Open Table In Sql Server Management Studio Express

Aug 24, 2006

Hello all.

I have uploaded a table into sql management studio express. However, when I right click on the table and try and open it, I get an error message saying;

"SQL Execution Error.

Executed SQL statement: select columnName1, columnName2 etc....

Error source: Microsoft. VisualStudio.DataTools

Error Message: Exception has been thrown by the target of an invocation"



Because of this error, I cannot manually edit the table. However, when I write a query running select * from Table X, the table does appear that way.

Any help regarding how to open the table would be very much appreciated!!

View 4 Replies View Related

How Do I Export My Database From SQL Server Management Studio Express

Aug 9, 2007

HiI am using SQL Server Management Studio Express to make my databases but I noticed if I make my database in Visual studios and go new Item and make a new database I see it in app_data folder and server express tab and if I make it in SQL Server Management Studio Express I only see it in the server explorer. So if I have to move my files to another computer how do I move my database easly with SQL Server Management Studio Express? Since when you make it with the visual studio the file gets stored with all the other files of your project so if you move it all to another computer you prob won't run into a problem. So how do I make it that so I can do everything in SQL Server Management Studio Express(since I like working in it) then export it into a file that I can then go into my app_data folder and add it is an exist item?  Thanks 

View 1 Replies View Related

Database Snapshot In SQL Server Management Studio Express

Oct 16, 2007

How do I set up a database snapshot and backup the database for Windows Server Update Services 3.0, that uses the "desktop" version of SQL server on the same server running Widows Server 2003? There does not seem to be a "Management Plans" sub-folder under the "management" folder in the Management Studio Express console- so that's probably my first request- how do I establish a "Management Plans" subfolder, then how do I (step-by-step) set up a backup of the SUSDB?

View 21 Replies View Related

Can't Attach Database Using SQL Server Management Studio Express

Apr 15, 2006

I am having a problem Attaching, well actually not being able to see a database when attempting to attach it. I suspect this is more of a security issue rather than a problem with Management Studio, but I can't figure out what is happening.

If I copy a database to Documents and SettingsAll Users... and attempt to attach I can see the file in the selection tree. This also is the case if I copy it to Documents and SettingsDefault User... But if I copy it to Documents and SettingsADynarski... which is the account I normally log into, when I expand the folder in the selection tree, nothing is visible. And the same thing occurs if I copy the file to Documents and SettingsGuest...

I've looked at the security settings and everything appears to be normal. This is on a box with XP Home and SQL Server Express. Can anyone tell me what I'm missing?

Thanks,

Al

View 9 Replies View Related

SQL Server Management Studio Express Export Database

Nov 10, 2007



Hello,

I'am a student and I'am using the Express version of the SQL sever Management Studio. The question that I have is:
Can I create a SQL database on my local computer and use this database on a other computer?
So I create a database on a laptop and want to export/import this on a desktop.

If this is possible can somebody sent met a tutorial ore something.

Thanks
Andre van Nijnatten

View 2 Replies View Related

Move Table In Sql Server Management Studio 2005 Express

Feb 7, 2007

I have two databases in sql server management studio and I want to move tables from one into another.  Is this possible?  and how?  Thanks
Andrew

View 3 Replies View Related

How Can I Backup The AdventureWorksLT Database To SQL Server Management Studio Express?

Jan 9, 2008

Hi all,

I just found out the name of AdventureWorksLT is in my SQL Server Server Management Studio Express, but the content of AdventureWorksLT database in my SQL Server Management Studio Express is gone. I saved the backup file of the AdventureWorksLT database in my C:Program filesMicrosoft SQL ServerMSSQL.1MSSQLackup folder. How can I backup the AdventureWorksLT database to SQL Server Management Studio Express again? Please help and advise.

Thanks in advance,
Scott Chang

View 1 Replies View Related

How To Backup A Database In Sql Server Management Studi Express Automatically

Mar 3, 2008

I come cross some post about how to backup a database in Sql Server Management Studio Express automatically. The scripts look like as below

USE [master]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_BackupDatabase]
@databaseName sysname
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sqlCommand NVARCHAR(1000)
DECLARE @dateTime NVARCHAR(20)
SELECT @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),111),'/','') +
REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','')
SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName +
' TO DISK = ''C:Backup' + @databaseName + '_Full_' + @dateTime + '.BAK'''

EXECUTE sp_executesql @sqlCommand
END



It throws that the DDL statement is not allowed. What's wrong with it?

View 5 Replies View Related

Repair Northwind Database In SQL Server Management Studio Express

May 7, 2007

Hi all,

Long time ago, I downloaded the Northwind and pubs databases from the Microsoft website (I do not remember the details of it) and installed these two databases together into the SQL Server Management Studio Express of my PC (Microsoft Windows XP Pro). I tried to learn an example of using "User Instance" (source code was from a book) on the Northwind database located in my SQL Server Management Studio Express. I just find out that my Northwind database has the title only and no tables at all. If I click on the "+" in front of the "Northwind", I got the following error message:

Microsoft SQL Server Management Studio Express



Failed to retrieve data for this request.(Microsoft SqlServer.Express.SmoEnum)



Additional information:

One or more files do not match the primary file of the database. If you are attempting to attach a database, retry the operation with the correct files. If this is an existing database, the file may be corrupted and should be restored from backup. (Microsoft SQL Server, Error: 5173)..



Please help and tell me how I can repair this Northwind database in my SQL Server Management Studio Express.



Scott Chang



P. S.



I deleted the name 'Northwind' in my SQL Server Management Studio Express, executed the "SQL2005DBScriptsInstnwind" program and I got the following error message: Msg 1802, Level 16, State 4, Line 1

CREATE DATABASE failed. Some file name listed could not be created. Checked related errors.

Msg 5170, Level 16, state 1, Line 1

Cannot create file 'c:Program FilesMicrosoft SQL ServerMSSQL.1DATAorthwindorthwind.ldf' because it already exist. Change the file path or the file name, and retry the operation.

Msg 15100, Level 16, State 1, Procedure sp_dboption, Line 64

The database 'Northwind' does not exist. Use sp_helpdb to show available database.

Msg 911, Level 16, State 1, Line 1

Could not locate entry in sysdatabases for database 'Northwind'. No entry found with that name. Make sure that name is entered correctly

View 5 Replies View Related

Database Connection Error In SQL Server Management Studio Express

Jan 18, 2008

Hello,

We are trying to connect the data base in SQL Server Management Studio Express using Operating System Xp.

The following error show during the connection time.

" Cannot open database "Test" requested by the login. The login failed. Login failed for user 'NT AUTHORITYSYSTEM'.

We have the login Id for sa and password. Connect to server it work properly.

Could you please give me the steps to resolve the problem.

Thanks,

Mahesh

View 2 Replies View Related

Uploading Database To Sever With Sql Server Management Studio Express

Jun 28, 2007

Hello,



I would like some help in uploading a database from my harddrive to a server using sql server management studio express.



If I try to attach it to the server, this program only looks at the files on this server and not on my harddrive. So how can I copy a sql database to my folder on the server.



I am sure it must be a simple problem, but I've been bizzy with it for about a day now. So, please advice.



Rgds,



Wouter.

View 7 Replies View Related

How Can I Attach AdventureWorks Database To SQL Server Management Studio Express?

Sep 25, 2006

Hi all,

I just downloaded AdventureWorks_Data.mdf, AdventureWorks_Data.ldf, AdventureWorksDW_Data.mdf, and AdventureWorksDW_Data.LDF files to the C:Program FilesMicrosoft SQL ServerMSSQL.1|MSSQLData folder of my Windows XP Pro PC. I tried to attach the AdventureWorks database in my SQL Server Management Studio Express in the following way: I clicked on SQL Server 2005 Express=>SQL Server Management Studio Express=>Right clicked on Databases=> clicked on "Attach..."=> "Attach Databese" showed up. But I can not type in anything under the MDF File Location, Database Name, Attach As, Owner, Status, Message!!!??? What is wrong in my way of doing the attachment of AdventureWorks database (described above)? Please help and advise.

Thanks,

Scott Chang

P. S. I do not have Microsoft Visual Studio 2005. Walkthrough: Install the AdventureWorks Database (http://msdn2.microsoft/en-us/library/ms31035.aspx) : To confirm your SQL Server data directory (Start=>All Programs, Microsoft Visual Studio 2005, Visual Studio Tools, Visual Studio 2005 Command Prompt) steps 1 thru 4 can not be applied to my SQL Server Management Studio Express. I read an SQL Express post dated 19 April 2006 and learned the above-mentioned way to attach the AdventureWorks database in the SQL Server Management Studio Express. But that way does not work for me.

View 4 Replies View Related

How To Import A Text Database File Into SQL Server Management Studio Express

Aug 21, 2007

I have a text file with a bunch of zip codes:  99546,"AK","Adak",162.70,55.20,.0099551,"AK","Akiachak",161.39,60.89,.0099552,"AK","Akiak",161.19,60.89,.0099553,"AK","Akutan",165.78,54.14,.00................... I want to import this in Sql Server Express.  Is it possible to do this using Management Studio Express?  If not,  does anyone know a script that would import the data?

View 3 Replies View Related

Using Microsoft SQL Server Management Studio Express To Export/copy Database?

Apr 11, 2006

How does one export/copy a database using Microsoft SQL Server
Management Studio Express?  At this time, I have an existing
database that I can access and run queries against.  However, I
cannot connect to it via Visual Wed Developer 2005 Express.  At
this time, I'm getting the following error message with the existing
database:

Login failed for user 'bigide2_gims2'.  The user is not associated with a trusted SQL Server Connection.

Next, I'm running everything locally.  If anyone can assist, it would be greatly appreciated and thanks in advance.

-Conrad

View 1 Replies View Related

Sql Express Copying A Database?

Aug 8, 2005

Hi All,I have a database that I would like to copy for another project. The instance is SQLEXPRESS, I have copied the MDF file, renamed and then copied it back but how to I attach this.I have read a small article about XCOPY but could really understand it, and are there limitation of doing it this way ... i just want an exact copy in the same instance ?Anyone got any links to tuttorials for doing this?Thanks in advancelee

View 1 Replies View Related

Built Database With SQL Server Management Studio Express, How Can I Quikly Add Test Data?

Apr 13, 2006

I've built my SQL Server Express database with SQL Serevr Management Studio Express, and now I want to enter some seed data to assist in building tha app around it. I cannot find an option to manage the data in SQL SMSX, like I used to with Enterprise Manager.
I don't want to have to write an app just to get test data in. Seems like this should be a common need. Am I missing something obvious here? Can't find any reference to this in a search of the forums.
Please help.
 

View 1 Replies View Related

I Imported A SQL Table Into SQL DataBase, But I Can Not Update This Table Even With SQL Server Management Studio

Jan 8, 2008

I imported a SQL Table into SQL DataBase, But I can not update this table even with SQL Server management Studio
When I change any data on mentioned table above, Red exclamation sign appears left of the record .
How can I correct this problem?
 Thanks.

View 1 Replies View Related

Common Table Expression (CTE):How To Delete A Wrong CTE That Is In SQL Server Management Studio Express (SSMSE)?

Feb 25, 2008

Hi all,

I ran the following CTE sql code:


Use ChemDatabase

GO

WITH PivotedTestResults AS

(

SELECT TR.AnalyteName, TR.Unit,

Prim = MIN(CASE S.SampleType WHEN 'Primary' THEN TR.Result END),

Dupl = MIN(CASE S.SampleType WHEN 'Duplicate' THEN TR.Result END),

QA = MIN(CASE S.SampleType WHEN 'QA' THEN TR.Result END)

FROM TestResults TR

JOIN Samples S ON TR.SampleID = S.SampleID

GROUP BY TR.AnalyteName, TR.Unit

)

SELECT AnalyteName, UnitForConc,

avg1 = abs(Prim + Dupl) / 2,

avg2 = abs(Prim + QA) / 2,

avg3 = abs(Dupl + QA) / 2,

RPD1 = abs(Prim - Dupl) / abs(Prim + Dupl) * 2,

RPD2 = abs(Prim - QA) / abs(Prim + QA) * 2,

RPD2 = abs(Dupl - QA) / abs(Dupl + QA) * 2

FROM PivotedTestResults

GO

//////////////////////////////////////////////////////////////////////////////////////
I got the following errors:

Msg 207, Level 16, State 1, Line 9

Invalid column name 'Unit'.

Msg 207, Level 16, State 1, Line 3

Invalid column name 'Unit'.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I guess that I had "Unit" (instead of "UnitForConc"), when I executed the sql code last time!!!???
How can I delete the old, wrong CTE that is already in the ChemDatabase of my SSMSE?

Please help and advise.

Thanks in advance,
Scott Chang

View 5 Replies View Related

How Can I Return A Database From The DataBase Explorer Of VB 2005 Express To The Object Explorer Of SQL Server Management Studio

Mar 3, 2008

Hi all,

I just realized recently that a database "XYZ" in the Object Explorer of my SQL Server Management Studio Express (SSMSE) is put in the Database Explorer of my VB 2005 Express for processing a Stored Procedure in executing the SELECT statements (not by using Input and/or Output Parameters) during the ADO.NET 2.0-VB 2005 Express programming, then the content of the database "XYZ" is not in the SSMSE. How can I return the database "XYZ" from the DataBase Explorer of VB 2005 Express back to the Object Explorer of SQL Server Management Studio Express (SSMSE) safely? Please help and advise.

Thanks in advance,
Scott Chang

View 6 Replies View Related

SQL Server Management Studio Express:Cannot Access Destination Table ‘dbo.FromExcel’in SqlConnection-VBExpress Programming(P.1)

Oct 18, 2007

Hi all,
In the Object Explorer of my SQL Server 2005 Management Studio Express, I do not have €˜Northwind€™ Database installed yet. I executed the following source code (that was copied from a book) in my VB 2005 Express:
/////////////////////----Form9.vb----//////////////////////////
Imports System.Data.SqlClient
Imports System.Data
Public Class Form9

Dim cnn1 As New SqlConnection

Private Sub Form5_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'Compute top-level project folder and use it as a prefix for
'the primary data file
Dim int1 As Integer = InStr(My.Application.Info.DirectoryPath, "bin")
Dim strPath As String = Microsoft.VisualBasic.Left(My.Application.Info.DirectoryPath, int1 - 1)
Dim pdbfph As String = strPath & "northwnd.mdf"
Dim cst As String = "Data Source=.sqlexpress;" & _
"Integrated Security=SSPI;" & _
"AttachDBFileName=" & pdbfph
cnn1.ConnectionString = cst

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Create a command to create a table
Dim cmd1 As New SqlCommand
cmd1.CommandText = "CREATE TABLE FromExcel (" & _
"FirstName nvarchar(15), " & _
"LastName nvarchar(20), " & _
"PersonID int Not Null)"
cmd1.Connection = cnn1

'Invoke the command
Try
cnn1.Open()
cmd1.ExecuteNonQuery()
MessageBox.Show("Command succeeded.", "Outcome", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn1.Close()
End Try

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Create a command to drop a table
Dim cmd1 As New SqlCommand
cmd1.CommandText = "DROP TABLE FromExcel"
cmd1.Connection = cnn1

'Invoke the command
Try
cnn1.Open()
cmd1.ExecuteNonQuery()
MessageBox.Show("Command succeeded.", "Outcome", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn1.Close()
End Try

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click


'Declare FromExcel Data Table and RowForExcel DataRow
Dim FromExcel As New DataTable
Dim RowForExcel As DataRow

FromExcel.Columns.Add("FirstName", GetType(SqlTypes.SqlString))
FromExcel.Columns.Add("LastName", GetType(SqlTypes.SqlString))
FromExcel.Columns.Add("PersonID", GetType(SqlTypes.SqlInt32))

'Create TextFieldParser for CSV file from spreadsheet
Dim crd1 As Microsoft.VisualBasic.FileIO.TextFieldParser
Dim strPath As String = _
Microsoft.VisualBasic.Left( _
My.Application.Info.DirectoryPath, _
InStr(My.Application.Info.DirectoryPath, "bin") - 1)
crd1 = My.Computer.FileSystem.OpenTextFieldParser _
(My.Computer.FileSystem.CombinePath(strPath, "Book1.csv"))
crd1.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
crd1.Delimiters = New String() {","}

'Loop through rows of CSV file and populate
'RowForExcel DataRow for adding to FromExcel
'Rows collection
Dim currentRow As String()
Do Until crd1.EndOfData
Try
currentRow = crd1.ReadFields()
Dim currentField As String
Dim int1 As Integer = 1
RowForExcel = FromExcel.NewRow
For Each currentField In currentRow
Select Case int1
Case 1
RowForExcel("FirstName") = currentField
Case 2
RowForExcel("LastName") = currentField
Case 3
RowForExcel("PersonID") = CInt(currentField)
End Select
int1 += 1
Next
int1 = 1
FromExcel.Rows.Add(RowForExcel)
RowForExcel = FromExcel.NewRow
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
Loop
Try
cnn1.Open()
Using sqc1 As SqlBulkCopy = New SqlBulkCopy(cnn1)
sqc1.DestinationTableName = "dbo.FromExcel"
sqc1.WriteToServer(FromExcel)
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn1.Close()
End Try

'Read the FromExcel table and display results in
'a message box
Dim strQuery As String = "SELECT * " & _
"FROM dbo.FromExcel "
Dim str1 As String = ""

Dim cmd1 As New SqlCommand(strQuery, cnn1)
cnn1.Open()
Dim rdr1 As SqlDataReader
rdr1 = cmd1.ExecuteReader()
Try
While rdr1.Read()
str1 += rdr1.GetString(0) & ", " & _
rdr1.GetString(1) & ", " & _
rdr1.GetSqlInt32(2).ToString & ControlChars.CrLf
End While
Finally
rdr1.Close()
cnn1.Close()
End Try
MessageBox.Show(str1, "FromExcel")

End Sub

End Class
///////////////////////////////////////////////////////////////////////
This is Part 1 (The length of input exceeds 50000 characters). Part 2 will be posted in this site shortly.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved