I'm making a WPF application with a local database,
I made the database with SQL server management studio, then I linked a .edmx file to the database I made.
Now if i wanna run my program on another PC i don't have that database anymore so it kinda crashes.
Can I copy my database file (.mdf) in my Debug folder and change my App.Config so it takes that database?
Becouse I wanna copy my program to a computer that dosn't have SQL server Management studio installed. Is that posible?
My App.Config looks like this atm:
<connectionStrings>
<add name="PRCEntities" connectionString="metadata=res://*/PRC.csdl|res://*/PRC.ssdl|res://*/PRC.msl;provider=System.Data.SqlClient;provider connection string="Data Source=DESKTOP-BERNARD\SQLEXPRESS;Initial Catalog=PRC;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>
Thx
You can copy the mdf but:
The target machine has to have SQL Server installed
You'll have to attach the mdf file
You'll need to change the connection string, either let the user that installs the application enter it or change the machine name to localhost but you might run into machines that have named instances and no default instance.
Related
I am new to SQL Server. I am doing the offline sync using SQL Server and sqlite DB. For that I followed the below tutorial SQL Server Installation. In this tutorial I am stuck on how to open the localhost service. When I run the service (localhost/AuroraSyncService.svc) in browser it shows empty.
For this I created the database AuroraSyncCn in my SQL Server Management Studio and created the new website in my IIS (internet information security).
MY coneection Strings:
<connectionStrings>
<add name="AuroraSyncCn" connectionString="Data Source=(local);Initial Catalog=SQLite-Sync.com;User ID=sa;Password=pass" providerName="System.Data.SqlClient" />
</connectionStrings>
here i tried connectionString="localhost/myservicefolde/aurorasyncservice.asmx;
Somebody help to solve this one.
From what I see your connection string should contain your database name (Initial Catalog=AuroraSyncCn).
If it's SQLExpress, instance name should probably be the same as the one mentioned by vasin1987 (server/serverinstance).
But from what I remember from ASP.NET, 'localhost' as Data Source should also be just fine.
Can you please show/write what you have in login window in MS SQL (Server name is what interest us the most):
I have problem to connect my application (on computer A) to another computer (computer B) that had the database (.mdf file).
This is my code
<connectionStrings>
<add name="HS_App.My.MySettings.DatabaseHSConnectionString"
connectionString="Data Source=Computer-B\SQLEXPRESS;AttachDbFilename=Computer-B\Users\Computer-B\Desktop\HS App\DBHS\DatabaseHS.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Computer A and B are connected via adhoc, and have the same environment ip address. Can I do that? Thanks in advance.
If you want to use a local SQL Server Express instance using AttachDbFileName for a database located on another computer it will not work: SQL Server requires local filesystem access because it does some interesting under-the-hood filesystem stuff with the database files (.mdf and the log files), so MDF files located on a network share (UNC path) or Internet location will not work, see here: http://msdn.microsoft.com/en-us/library/ms254500(v=vs.80).aspx
System.Data.SqlClient resolves the substitution strings into full paths against the local computer file system. Therefore, remote server, HTTP, and UNC path names are not supported. An exception is thrown when the connection is opened if the server is not located on the local computer.
If you want to connect to an already-running SQL Server Express instance on another computer over TCP, then you need to set-up TCP connections on that server first. Note that you cannot use AttachDbFilename either because that option only applies to "user instances" of SQL Server Express.
we decided to start a new project using the Microsoft SQL Server R2 under Win7. I installed SQLEpress R2 on my system and it was decieded to called it BEACONExpress. At first we could not get it to run, until we had our Domain SysApp come in and set the ownership to my login. Now I was able to use SQL Management Studio to create the Database. I even added some Tables to it. Then I fired up VS 2010 and created a test program. When I try and access the new database, VS returns this error "The file can not be opened because it is being used by another process. Please close all applications that might access this file and try again."
If I attempt to create a new database under App_Data it returns this error. A network-related or instance-specific error occurered while establishing a connection to SQL server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified).
The connectionStrings in Web.config says
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename= |DataDirectory|aspnetdb.mdf;User Instance=true"
provideName=:System.Data.SqlClient" />
</connectStrings>
I found the database at C:\Program Files\Microsoft SQL Server\MSSQL10_50.BEACONEXPRESS\MSSQL\DATA\BeaconDB.mdf
I tried changing SQLEXPRESS to MSSQL10_50.BEACONEXPRESS but it had no affect. I have been reading here and on other forums trying to determine what is wrong but so far have not found an answer.
Have you verified that the Windows 7 firewall is configured to let you access the SQL Server? I had the same problem when triyng to access a database on my server at home, with Win7 x64.
Also, you should be sure to run the version SQL Server 2008 R2, because if R2 is not installed and all the updates are not installed, it will not work on Win7 x64
Maybe this link can help you:
http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/1bb10896-27ed-4469-81e0-a84f4fba68c9
http://blogs.msdn.com/b/sqlexpress/archive/2005/05/05/415084.aspx
Change your connection string element to
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=BeaconDB"
(Where BeaconDB is the name of your database)
I am currently creating a data drivien wpf application, and everything works perfectly as a charm on my development computer (the computer I used to create the program). Also, when I move the app from the Release directory and copy to my local machine, it works perfectly. But on the other hand, when my application reaches other users, it stops connecting to databases completely.
I don't get how this is as I have my connection string set properly, which is:
<connectionStrings>
<add name="MyConnectionStrint"
connectionString="Data Source=MyServerIP\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Which is an XML Config file located in the root directory. As soon as the program is given to someone else, it stops functioning completely; no data is received or sent.
Could this be because of something like, they need MS SQL Server or something for it to connect to my remote database? I even tried connecting to the database using SQL Server Management Studio, which fails to work on other PCS, but for some reason works on mine and no one else's. This is a problem as this program is meant to be distributed to at least 15 people. Any Ideas as to what Is causing this?
Any help would be appreciated, thanks.
Is the database server on your development machine ?
If so, then you have to enable the tcp/ip configuration in your SQL Server Configuration Manager.
If that's not enabled then your server will not be accessible outside of the machine on which it resides.
hi
i`m using visual basic express 2010 and SQL server 2008 R2
this is my problem
i create database in sql, then i connect to database by visual basic.
like
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections></configSections>
<connectionStrings>
<add name="WindowsApplication1.My.MySettings.BPdataConnectionString"
connectionString="Data Source=.\SQLBAC;AttachDbFilename=G:\SQLSERVER\MSSQL10_50.SQLBAC\MSSQL\DATA\BPdata.mdf;Persist Security Info=True;User ID=sa;Password=martin;Connect Timeout=30;User Instance=False"
providerName="System.Data.SqlClient" />
<add name="BPdataEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLBAC;AttachDbFilename=G:\SQLSERVER\MSSQL10_50.SQLBAC\MSSQL\DATA\BPdata.mdf;Persist Security Info=True;User ID=sa;Password=martin;Connect Timeout=30;User Instance=False;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
everything is working but if i will use it in other PC then database directory and SQL server name will be different...
so i need to ask program before start for server name, database name...
If you don't know the path of the database file(s), then you will need to ask the user. If you are creating the database file yourself, then you should know the location. If SQL Server is running locally, then you can use . for the source and that will resolve to the local machine.
One thing you can do in AttachDbFilename is start start off with |DataDirectory| (i.e. AttachDbFilename=|DataDirectory|\Folder1\MyDatabase.mdf) and that will resolve to the data directory of your application; with most winforms application, this is the folder that the executable is in, but some technologies (like ClickOnce) will have the data directory located elsewhere.
HTH
EDIT:
If it turns out you do need to build the connection string at runtime, there are classes in the framework that will help with that. The SQL Server version is described here at MSDN: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx