SQL Server Express connection to another computer by changing exe.config - vb.net

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.

Related

Connecting to SQL Server Express via ip

I am using SQL Server 2008 R2 Express and EF 6.
Here is my connection string which I place in app.config:
<connectionStrings>
<add name="StructuralSynthesisConnection"
connectionString="data source=192.168.0.103\sqlexpress;Network Library=DBMSSOCN;initial catalog=StructuralSynthesisDB;integrated security=True;pooling=False;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
It connects only to current computer (192.168.0.103) ONLY with ip I mentioned (it`s my local ip using wifi). When I try to connect from another computer or/and with my real ip it fails.
I turned off windows firewalls, checked default sql port (1433), no dynamic ports, tried connection string with port. Nothing helped. Also (of course) I checked my internet connection and work of SQL Server Express on all devices I am using. They are all in local (wifi) network, maybe it makes some difference?
Ok, you should check this https://blogs.msdn.microsoft.com/walzenbach/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008/.
I Think it has a few configuration that you did not mention and how to implement it.
A few month a ago i had the same problem and i set everything with the correct configuration and i did not get the connetion, and my problem was that my Antivirus was bloking the connetion.
I hope it help.

SQL Server Database Connection in VS 2010

I have completed my program in MVC in VS 2010. In the connection string I have the following
<add name="RacePaceDBContext"
connectionString="data source=XX.XXX.XX.XXX,1433;Initial Catalog=RacePaceDataNew;Persist Security Info=True;User ID=user;Password=password;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
Which connects to a SQL Server running on an EC2 instance on Amazon AWS.
The program runs fine and the connection works great. The program connects and creates/reads data etc.
However, I am not sure why when I try "Connect To Database" in the server explorer on the left, and fill in the same settings it just doesn't connect. Any ideas why this would be different? As want to be able to log in and see my tables, data etc without having to log onto AWS. The same is true when I use MySQL Workbench to try connect - it gives me an error telling me the server isn't accessible.
it might firewall issue, Please make sure your client can connect to xx.xxx.xx.xxxx:1433.
You can also refer this : https://forums.aws.amazon.com/thread.jspa?messageID=435146
Hope this helpful.

Accessing Server under Windows 7 x64

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)

WPF application with local database

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.

Cannot connect to database from wpf outside development machine

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.