I'm trying to develop multi client in C# with SQL Server 2008 data Base, after made setup file and install it to client I cannot access DataBase in server. I used LINQ to Connect DataBase and have App.config xml file in my project which ConnectionString Declare there and I after installing the application I change that XML file's ConnectionString to right way(Server name and sql instance name), but this change doesn't have any impact, whats the problem maybe have my solution?
If any one has experience about developing multi client application share with me.
and also How can I change scope in project properties from Application to User, It's may be solve my problem
Thank you
In this project we use LINQ to connect Database to server, and we can get right Database address dynamically from User Interface and use it in constructor of DataContext:
public DataClasses1DataContext(string connection)
And then it don't care in embed connection string, its use only that connectionString in their constructor.
If the error mentions "provider: Named Pipes Provider", then your application is trying to connect via named pipes to your SQL Server, is that what you want? You can prefix the server name with tcp: to force TCP/IP usage instead i.e. Server=tcp:ServerName if you wish to use TCP.
If you want to use named pipes it is possible that support for it is turned off on the server, I believe it is disabled by default. You would need to enable it via the SQL Server configuration manager program on the server, in the network configuration, protocols section.
hmmm, hard to say without the connection strings or error message, but some ideas....
When you change the app.config, restart app to verify changes.
Try pinging the server from the where the app is being installed.
Check firewall settings. shared network.
Use your new connection string on your development machine on the same network if local.
Related
I'm deploying a wpf application and I'd like to know how is the best way to connect to a database.
For example after I install my application I need to set a connection string to connect with a SQL Server Express.
I read a thread that told it's possible to find SQL Servers installed on a machine, so after I find it, how do I connect it programmatically?
An another thing I thought is, there is a file which I can read an write a connection string as web.config in asp.net?
I know that there is an app.config file but after I deploy it I guess it became inaccessible!
Nothing wrong with putting SQL Server, especially Express, on the same machine if it's a smallish application. There's also the 'localdb' feature.
Anyway, this bit of code will find all instances of SQL Server on your network. You can then build a window to display the results, let the user pick a server, and construct a connectionstring from the results. Note that firewalls etc on the server can get in the way of this process - typically you get the server name returned but no other info. You can fix this by adding exceptions to the firewall.
private DataTable FindServers()
{
System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance;
DataTable dt = instance.GetDataSources();
return dt;
}
These days database layer should be separated from application by DataService or MicroService. Which would be the data access layer.
If you dont need that level of separation and still thinking about application that connects to database directly, I would suggest to use configuration to store connection strings as you probably like to cover scenario where database is not located on same server as WPF application.
The configuration file for non-web application is called app.configand is exactly the same as web.config for web applications.
Problem with auto-finding installed sql server instaces is simple: what if there are two instances installed on machine where you start your app? How the app will know which to use?
I have made a Wpf application and i am using linq to SQL classes also i have made my database in SQL server 2012 so is there any way that i can deploy my application in such a way that it will run on other PC's?
Check your app.config file. Make sure your connection string contains:
valid DataBase address
Valid credential for the db
As your update:
whenever i make setup file and run on another pc it give me exception
because sql server isnt installed on that pc
Either you need to deploy a database in internet, accessable by your app. Or you have to use an embedded sql db (e.g. add a db.mdf to your solution). I think this suit you better.
I have developed a winform application in C#.net and using SQL Server 2008.
My application inserts and updates values into database.
Is it possible to install the application on a another system which doesn't have sql server on it?
Imagine using sql azure. Cloud based sql server. The database is never on the same physically computer. It's all down to the connection string.
With an on premise database you need to make sure the database allows external connections, maybe opening up firewall etc. then make sure the connection string is set correctly on the application to talk to external database.
You can even configure to change the connection string as required pointing at different databases depending on the individual requirements.
Scott
Yes, you can. You can access the DB remotely by referring remote DB server in connection string.
It is possible, if you are looking to run the application on machine that is running on the same Domain as the SQL Server and has privileges to the SQL Server.
I am developing C# windows application first time.
Que 1 - ) I have developed my windows application which uses SQL server 2008 using below connection string..
Data Source=myMachineName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
But When I created setup of my application and installed it to another computer then it is throwing error of could not establish connection with SQL server..
I guess this error is because of my connection string as it is specific to my computer and installing it to another computer will not work..
Hence How can I make my connection string which will work with any computer..
Que 2 - Do I need to attach schema file with my setup as How my database will be created into the other computers??
This might be silly qustion but as I am doing this first time , i dont know about this all.
Regards,
Mahesh
You should place your web config in app.config file which is in xml format.
And read it from your code.You can easily change app.config file through notepad according to machine.
Yes must have your schema script in setup if you want to create it from setup.Otherwise you create database manual on client machine.
If you've used SQL Server on your development machine, it has to be installed on every computer that will be using your app. There are several options to resolve this issue:
If your app doesn't need access to a central sql server (for example your app just keeps track of users DVDs), use SQL Server Compact Edition instead and embed it to your app
If your app needs some kind of a centralized data, get a dedicated SQL server first, install there everything you need and in your app change your current myServerAddress to the address of the server. Note that the server needs to be accessible from remote locations (some restrict access to localhost!).
Que 2 - Do I need to attach schema file with my setup as How my
database will be created into the other computers??
Again, multiple options. For instance, you can export your database to a .sql file (Right click on the db in your DB explorer and select option Publish to provider) and then import it using a sql manager on other computers. Or maybe you can create a .cs installation script, that will do the same job using C# code.
Edit based on OP's comments:
Example links for solutions:
question1: Embedding SQLServer CE in an installer
question2: http://support.microsoft.com/kb/307283
Okay that's fine but will my current Connection string work in that case as the DataSource
is my specific machine name
Of course not, you'd have to change it to point to the SQL Server CE database file. Probably the best way is to not hardcode it, but use a relative path to the database. It looks like this for instance:
Data Source=|DataDirectory|\MyDb.sdf, where |DataDirectory| points to the App_Data folder of your application.
Also plese see the error screen map i have attach with the question..
Your error is quite clear - there was a problem establishing a connection to your database. It either doesn't exist or isn't accessible from your current machine.
There's no particular problem, I just wanted to ask whther I'm doing it right or wrong.
I have connection string stored in Settings.Default.ServerConnection property on which rely all DB-related objects. I also use auto-generated TableAdapters for server-side stored procedures (SQL Server 2008 R2 Express) with Connection property set to use mentioned connection property. There is a settings form where I can setup a connection to any server on the local network (using SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources()) and store it in app's settings.
So I was wondering if it's the right approach of doing such thing or not because when app is executed for the first time it's still able to connect to SQL server without even configuring the connection (Data Source set to (local) by default).
If I'm understanding the question... :-)
Your app is able to connect to local because that is the how its bound in its current environment (say it was a remote IP, it wouldn't work).
Storing connection string information in the config file (e.g. app.config) is a great idea, because it can be changed on the fly without a rebuild.