I have Visual Studio 2010, with SQL EXPRESS which came with VS2010 from what I understand. I built a database in my VB.NET project, and am trying to copy data from the corporate SQL SERVER to my VB.NET created database (SQL EXPRESS).
Below I've included my script, with both connection strings. The SQL SERVER version works, but not the SQL EXPRESS one. If anyone could led me in the right direction, it would be much appreciated.
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'SQL EXPRESS COnnection String
Dim con As SqlConnection = New SqlConnection("Server=OVP-L-R8MXE5M\SQLEXPRESS;" & "Database=dbTest;" & "Trusted_Connection=TRUE;")
'SQL SERVER COnnection String
'Dim con As SqlConnection = New SqlConnection("Server = ***-*-*******;" & "Database = CMP;" & "Trusted_Connection=TRUE")
con.Open()
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO dbTest.cbo.tblFactSales (BILLTO,BRANCHPLANT,COMPANY,DATASRC,DATATYPE,FRTHANDLE,MODE,ORDERTYPE,ORIGINPLANT,PRODUCT,RPTCURRENCY,SALESDATA,SHIPTO,TIMEID,SIGNEDDATA,SOURCE ) " & _
"SELECT CMP.dbo.tblFactSales.* " & _
"FROM CMP.dbo.tblFactSales " & _
"WHERE DATATYPE='FORECAST' AND TIMEID='20120700'", con)
cmd.ExecuteNonQuery()
MessageBox.Show("Records Moved Successfully.", "Move Complete", _
MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
End Sub
Last edited by S37N; Jul 19th, 2012 at 02:32 PM.
Reason: typo
so sorry, forgot the most important part...
When I try to connect with the SQLEXPRESS connection, the error reads: Cannot open database dbTest requested by the login. The login failed. Login failed for user ****
it's my corporate laptop. un/pw should be identical... i think :P
Well, it's saying the login is incorrect. It looks like you're trying to use Win auth to login into the db. I'd start by trying to connect to the db through SSMS first. If it throws the same error with smss then we have a prob.
Well, it's saying the login is incorrect. It looks like you're trying to use Win auth to login into the db. I'd start by trying to connect to the db through SSMS first. If it throws the same error with smss then we have a prob.
i cant see the db from SSMS. The only dbs i see when i log into SSMS are the system dbs (master, model, msdb, and tempdb) i created this db inside visual studio.
Originally Posted by smendoza
Oh and whats the error number sql server is returning like Msg 18456, Level 14, State 1
Here's the message info I get from Visual Studio
Msg: 4060
Level: I do not know where to find this.
State: 1
I agree with szlamany..... I'd start but getting the db installed in instance on your pc. I usually create my DB's with SSMS. Once you have the db running on the instance you should be fine, you might need to enable remote connections if you haven't already.
btw - I always use BACKUP and RESTORE to move DB from production server to test servers
Something like this
Code:
--drop database stufiles
/*
BACKUP DATABASE Stufiles
TO DISK = 'C:\SQL Backup\Stufiles.bak'*/
RESTORE FILELISTONLY
FROM DISK = 'd:\Stufiles_backup_201203292100.bak'
RESTORE DATABASE Stufiles
FROM DISK = 'd:\Stufiles_backup_201203292100.bak'
WITH MOVE 'Stufiles_data' TO 'd:\SQL data\Stufiles.mdf',
MOVE 'Stufiles_log' TO 'd:\SQL Logs\Stufiles.ldf'
The BACKUP is commented out at the top of the script - I run that on the production server...
Then bring back a .BAK file and restore it making sure to designate nice intelligent locations for the MDF and LDF to appear into.
RESTORE FILELISTONLY is just that - displays a file list in the query response pane - so you can see what the "logical" names of the DATA and LOG sections are in the DB.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
ok, perhaps im using the incorrect terminology. here's what I did in Visual Studio, step by step.
Under Server Explorer, on Data Connections, I clicked "Add Connection".
I change Data Source to Microsoft SQL Server Database File.
I typed in my database name (dbTest) for Database file name.
Selected "Use Windows Authentication".
Test Connection failed, since it was a new database, so I clicked OK.
It then notified me that I was creating a NEW database.
Once database appeared in Server Explorer, I created right-clicked on :"Tables", and selected "Add new Table".
I have copied some data manually (copy/paste) into this table from EXCEL, and I can right-click the table, and can create Queries against it through Server Explorer, so it's clearly has data in it.
I have logged into SSMS SEVERAL times, and dont see this database ANYWHERE, only the system databases that come with SQL EXPRESS
btw - I always use BACKUP and RESTORE to move DB from production server to test servers
Something like this
Code:
--drop database stufiles
/*
BACKUP DATABASE Stufiles
TO DISK = 'C:\SQL Backup\Stufiles.bak'*/
RESTORE FILELISTONLY
FROM DISK = 'd:\Stufiles_backup_201203292100.bak'
RESTORE DATABASE Stufiles
FROM DISK = 'd:\Stufiles_backup_201203292100.bak'
WITH MOVE 'Stufiles_data' TO 'd:\SQL data\Stufiles.mdf',
MOVE 'Stufiles_log' TO 'd:\SQL Logs\Stufiles.ldf'
The BACKUP is commented out at the top of the script - I run that on the production server...
Then bring back a .BAK file and restore it making sure to designate nice intelligent locations for the MDF and LDF to appear into.
RESTORE FILELISTONLY is just that - displays a file list in the query response pane - so you can see what the "logical" names of the DATA and LOG sections are in the DB.
i dont need the whole table, but rather a subset. there's ~130 million rows in the table. I only need ~300K. if i cant figure it out, I may have to do that.
You created the DB from within VS - that means VS put it someplace that it's hiding from you. You could probably hunt around the DATA CONNECTIONS in the SERVER EXPLORER with right-clicks and looking at properties and what not...
But why not create it within SSMS? So you know it's a DB attached to the SQL EXPRESS instance you know of?
Or - can you open a query window from within VS? I never tried that as I prefer the actual SSMS tool for working with a SQL instance.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
btw - you might want to edit that image - I see you wanted to redact specific info on your username...
Let's get you so you can create the DB from within SSMS - you seem hell bent on working with the DB from within SSMS - so let's make it there in the first place.
Who created this SQLExpress instance? Who installed it? What username? Was it a domain username?
Are you an admin on this workstation? Can you go into the SECURITY branch in SSMS and see un's?
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
ok, perhaps im using the incorrect terminology. here's what I did in Visual Studio, step by step.
Under Server Explorer, on Data Connections, I clicked "Add Connection".
I change Data Source to Microsoft SQL Server Database File.
I typed in my database name (dbTest) for Database file name.
Selected "Use Windows Authentication".
Test Connection failed, since it was a new database, so I clicked OK.
It then notified me that I was creating a NEW database.
Once database appeared in Server Explorer, I created right-clicked on :"Tables", and selected "Add new Table".
I have copied some data manually (copy/paste) into this table from EXCEL, and I can right-click the table, and can create Queries against it through Server Explorer, so it's clearly has data in it.
I have logged into SSMS SEVERAL times, and dont see this database ANYWHERE, only the system databases that come with SQL EXPRESS
Maybe I'm more lost than I initially thought.
You just created the physical data file. You still need to attach the physical data file to the instance of the sqlserver.
btw - you might want to edit that image - I see you wanted to redact specific info on your username...
Let's get you so you can create the DB from within SSMS - you seem hell bent on working with the DB from within SSMS - so let's make it there in the first place.
Who created this SQLExpress instance? Who installed it? What username? Was it a domain username?
Are you an admin on this workstation? Can you go into the SECURITY branch in SSMS and see un's?
im only worried about redacting our company domain, but thank you.
i dont really care which method i use, but im new at this, so im learning as i go. in the end, i would like to access my "test" dbs from both VS & SSMS.
im just a developer, and am not listed an an admin on the machine. our Technical Services dept set it all up, so I would assume it was a domain username.
screenshot of security tree within SSMS attached. my UN is NOT listed anywhere.
will i need to remove all dbTest references within Visual Studio, and recreate my db in SSMS, or is there a way to make SSMS recognize the dbTest I have made already?
thank you so much for helping me out. as i said, i'm learning. ive been writing VBA for access & excel for a few years, but this is my first attempt at VB.
i may have to wait until monday. they gave me admin rights to the computer, but I still get a permissions error in SQL, just like before. thanks again for your help.
it does not seem like i have proper access to SQL. i created a login, and was not able to add dbCreator role to it. when I try to delete the user I just made, it tells me i dont have access.
here's what mines looks like on mine, which is on a domain. the \youngje login is the one I just tried to make, and add dbCreator to. it errored out saying I didnt have permission to do that, but creatoed the user anyways. when i try to delete the user, it tells me I dont have permission.
not exactly sure, but I think it was a problem with the instance owner. I didnt have access to create or change anything. I suggested a fresh install under my UN, based on a few posts I read, and it seems to have worked.